引用WCF服务的两种方式.
2009-05-18 10:55
309 查看
1.在项目的ServiceReferences.ClientConfig文件中加入WCF服务定义,如下:
在CS文件中,使用如下代码引用WCF服务
第二种方式:在CS文件中,直接定义WCF服务,代码如下:
以上两种方式都能设用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服务,比如第一种方式,如果没有定义配置文件,则会报 找不到键值的错误提示.
相关文章推荐
- WCF 动态生成 不用增加引用两种方式
- 记录:Web无引用无配置方式动态调用WCF服务
- WCF服务使用(IIS+Http)和(Winform宿主+Tcp)两种方式进行发布
- WCF客户端编程-基于服务引用方式
- WCF服务部署到IIS上,然后通过web服务引用方式出现错误的解决办法
- 展示两种WCF服务通信方式
- 关于WCF引用方式之WCF服务寄宿控制台
- 展示两种WCF服务通信方式
- WCF引用方式之IIS方式寄宿服务
- Dynamics CRM 非声明验证方式下连接组织服务的两种方式的性能测试
- SilverLight通过Net.TCP(NetTCPBinding)方式调用WCF服务
- Arrays.sort()使用两种方式(Comparable和Comparator接口)对对象或者引用进行排序
- java值传递的两种方式:值传递和引用传递
- 启动服务的两种方式
- WCF两种方式
- WCF---客户端引用服务时List<T>变为数组T[]的问题
- WCF入门教程(四)通过Host代码方式来承载服务
- 解决 Silverlight 调用 WCF 服务 跨域访问 和 Silverlight 引用服务后配置文件不加载的问题
- WCF技术剖析之二十九:换种不同的方式调用WCF服务[提供源代码下载]
- 结构体变量成员的引用(两种方式)