通过Svcutil.exe 工具生成代理类调用
1.找到如下地址“C:WindowsSystem32cmd.exe” 命令行工具,右键以管理员身份运行(视系统是否为win7 而定)
2.输入如下命令:"C:Program FilesMicrosoft SDKsWindowsv7.0AinSvcUtil.exe" /out:C:WCFClintClientCode.cs /config:C:WCFClintapp.config http://localhost:81/WCFServiceTest/CNPatentSearchService.svc
说明:
参数1: “C:Program FilesMicrosoft SDKsWindowsv7.0AinSvcUtil.exe” ,是指 SvcUtil.exe 工具的地址
参数2: “C:WCFClintClientCode.cs ” ,是指生成的代理类输出存放到的地址
参数3: “C:WCFClintapp.config ” ,是指存放到调用WCF服务程序目录下的配置文件的输出存放地址
参数4: “http://localhost:81/WCFServiceTest/CNPatentSearchService.svc ” ,是指部署到IIS 的WCF服务的地址
3.运行以上命令后,会在"C:WCFClint"目录下生成两个文件,ClientCode.cs 和app.config
(C:WCFClintapp.config 中已经为我们配置好了WCF服务的根节点等必须的信息,当然,如果您也可以自己对部分参数进行修改)
4.将ClientCode.cs 和app.config 添加到需要调用WCF服务的项目中
5.在需要调用WCF服务的项目中添加对"System.ServiceModel" 和"System.Runtime.Serialization" 程序集的引用
6.自此就完成了部署和代理类生成的所有操作,我们只需要在项目中实例化 ClientCode.cs 中的服务类 ,并调用其中的方法即可
Microsoft (R) Service Model Metadata Tool
[Microsoft (R) Windows (R) Communication Foundation, Version 3.0.4506.2152]
Copyright (c) Microsoft Corporation. All rights reserved.
Attempting to download metadata from 'http://local:8001/womaiapp/wmsServic
eCancelAllocateout?wsdl' using WS-Metadata Exchange or DISCO.
Generating files...
C:WCFClintClientCode.cs
C:WCFClintapp.config
C:WINDOWSsystem32>exit