记录下
首先用svcutil.exe把指定wcf接口的信息下载下来。
生成代理类
比如说接口地址为
http://localhost:6666/Service1.svc
以管理员身份打开cmd
执形
"C:Program Files (x86)Microsoft SDKsWindowsv7.0ABinSvcUtil.exe" /out:C:WCFClintClientCode.cs /config:C:WCFClintapp.config http://localhost:6666/Service1.svc"
注意上面的命令要用""括起来
然后C:WCFClint这个目录下会生成该接口信息文件(一个.cs文件,一个config文件)
把他们粘贴进程序中
本文以console程序为例:
//看生成的配置文件选择绑定类型(客户端config文件,用svcutil生成的)
WSHttpBinding binding = new WSHttpBinding();
binding.Security.Mode = SecurityMode.None;
Service1Client service = new Service1Client(binding, new EndpointAddress("http://localhost:6666/Service1.svc"));
//此时用service对像就可以愉快的调接口里面的方法了。
service.sb();
service.Close();
如果缺System.Runtime引用,请自行添加 程序集->框架 里面有