記錄下
首先用svcutil.exe把指定wcf接口的信息下載下來。
生成代理類
比如說接口地址為
http://localhost:6666/Service1.svc
以管理員身份打開cmd
執形
"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\SvcUtil.exe" /out:C:\WCFClint\ClientCode.cs /config:C:\WCFClint\app.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引用,請自行添加 程序集->框架 里面有
文章列表
留言列表
