您的位置:首页 > 其它

引用WCF服务的两种方式.

2009-05-18 10:55 309 查看
1.在项目的ServiceReferences.ClientConfig文件中加入WCF服务定义,如下:

<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
<security mode="None" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:2442/Service1.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService" contract="ServiceReference1.IService1"
name="BasicHttpBinding_IService" />
</client>
</system.serviceModel>
</configuration>


在CS文件中,使用如下代码引用WCF服务

var client = new ServiceReference1.Service1Client();


第二种方式:在CS文件中,直接定义WCF服务,代码如下:

Binding binding = new BasicHttpBinding();
EndpointAddress endPoint = new EndpointAddress(
"http://localhost:2442/Service1.svc");

Service1Client client = new Service1Client(binding, endPoint);


以上两种方式都能设用WCF服务,比如第一种方式,如果没有定义配置文件,则会报 找不到键值的错误提示.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: