The service has been created.
To test this service, you need to create a client and use it to invoke the service. You can do this by using the SvcUtil.exe tool from the command line using the following syntax:
svcutil.exe http://localhost:3017/mainservice.svc?wsdl
You can also access the service description as a single file:
http://localhost:3017/mainservice.svc?singlewsdl
This generates a configuration file and a code file that contains the client class. Add these two files to the client application and use the generated client class to invoke the service. For example:
class test{ staticvoid Main () { new mainserviceclient (); // Use the "client" variable to invoke the operation on the service. // always close the client. Client. Close (); }}
Find the Tools button on the VS Toolbar-"External Tools"-"add"
Title: SvcUtil
Command: C:\Program Files (x86) \microsoft Sdks\windows\v8.0a\bin\netfx 4.0 Tools\svcutil.exe
Initial directory: $ (ProjectDir)
Click "Apply"-"OK".
Go to the VS toolbar and find "Tools"-click on the "SvcUtil" button:
Input parameter: "HTTP://LOCALHOST:3017/MAINSERVICE.SVC?WSDL" service address.
The point "OK" will generate two files in the project root directory,
Copy the contents of the <system.serviceModel> node in the Output.config file to the last location in the </configuration> node of the Web. config file.
Called in the controller:
PublicActionResult Index () {viewbag.message="modify this template to quickly launch your ASP. NET MVC application. "; Mainserviceclient Client=Newmainserviceclient (); //Use the "client" variable to invoke the operation on the service. stringVALUESTR = client. GetData (1688); Viewbag.valuestr=Valuestr; //always close the client. client. Close (); returnView (); }
Page display:
Copyright, reproduced Please specify the source: http://www.cnblogs.com/OnlyDreams/articles/4386571.html
Visual Studio 2012 uses svcutil to reference a WCF service in a MVC4 client