Two common methods are used to call a WCF Service: one is to use the code generation tool svcutil.exe or add a service reference. The other is to directly create a service proxy object through ChannelFactory for service calling.
To put it simply, how does one call the service through svcutil.exe:
SvcUtil.exe is a command line tool located in the C: \ Program Files \ Microsoft SDKs \ Windows \ v7.0A \ bindirectory. You can add SvcUtil.exe to VS2010 to facilitate future use: select External Tools from the Tools menu of VS2010, as shown in figure
Click "Export" and enter svcutilin the titlefield. In the commandbar, select the directory where svcutil.exe is located. In the Initial directory column, select the generated client code and directory of the configuration file, select Prompt for arguments, Close on exit, and click "OK.
After adding the metadata, click SvcUtil in the VS2010 menu and enter the URL of the service endpoint that provides metadata, as shown in figure
Click OK. The displayed command line displays the success or failure information and related information. 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 copy the output. config is changed to app. config.
For more commands on SvcUtil, see MSDN: http://msdn.microsoft.com/zh-cn/library/aa347733%28VS.90%29.aspx