Wcfuses svcutil.exeto generate the client proxy class and configuration file (), wcfsvcutil.exe
Two common methods are used to call a WCF Service:
1: one is to use the code generation tool svcutil.exe or add a service reference.
2: one is to directly create a service proxy object through ChannelFactory for service calling.
In this document, the svcutil.exe tool is used to generate the proxy class and the corresponding configuration file.
I. Use the cmd command line to generate the proxy class and the corresponding configuration file
1. Find the "C: \ Windows \ System32 \ cmd.exe" command line tool, right-click it and run it as an administrator (depending on whether the system is win7)
2. Enter the following command:
C: \> cd C: \ Program Files \ Microsoft SDKs \ Windows \ v7.0A \ bin
C: \ Program Files \ Microsoft SDKs \ Windows \ v7.0A \ bin> SvcUtil.exe/out: clientCode. cs
/Config: \ app. config http: // localhost: 62026/CalculatorService. svc
Note:
Parameter: "C: \ ClientCode. cs" refers to the address where the generated proxy class output is stored.
Parameter: "C: \ app. config" refers to the output address of the configuration file stored in the directory that calls the WCF Service Program.
Parameter: "http: // localhost: 81/WCFServiceTest/CNPatentSearchService. svc" refers to the address of the WCF Service deployed to IIS or the address of the hosted WCF Service.
3. After running the preceding command, two files, ClientCode. cs and app. config, will be generated in the "C: \" directory.
(C: \ app. config has already configured required information such as the root node of the WCF Service for us. Of course, if you can modify some parameters yourself)
Ii. Add svcutil.exe to VS external tools, and then call the added tool in VS to generate
1: Add Svcutil tool in VS2015
1): In VS2015ToolsSelectExternal tools, Such
2): In the pop-up window, clickAdd, Such
3 ):TitleField InputSvcUtil,CommandSelectSvcUtil.exeDirectory,Initial directorySelect the directory of the generated client code and configuration file,
SelectedPrompt for parameter input, Not selectedClose upon exit, ClickOKComplete adding.
2: After adding the SDK, click VS2015.ToolsUnder the menuSvcUtil, Such
InParametersEnter the URL of the service endpoint that provides metadata, as shown in figure
ClickOKThe success or failure and related information are displayed in the pop-up command line. For example
If successful, two files will be generated. One is the cs file that contains the Contract on the server and the local proxy class corresponding to the service on the server, and the other is the WCF configuration file.
Copy the two files to the project and rename output. config to app. config.
References:
Http://blog.163.com/ningbao911@126/blog/static/3743053820132133616282/
Http://www.cnblogs.com/luowanli/archive/2012/02/24/markeluo_wcfiis.html
Http://www.cnblogs.com/zfanlong1314/archive/2012/03/23/2413122.html