WCF服务的引用是一个比较简单的方式。我们可以通过两种方式来实现引用WCF服务。在这里,就向大家详细讲解引用WCF服务的方法。#t#

我们提供的服务有:成都网站设计、成都网站建设、外贸网站建设、微信公众号开发、网站优化、网站认证、江宁ssl等。为近1000家企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的江宁网站制作公司
引用WCF服务1.在项目的ServiceReferences.ClientConfig文件中加入WCF服务定义,如下:
- view plaincopy to clipboardprint?  
 - < 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>   
 - < 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服务
 
 
 
  
  
  - view plaincopy to clipboardprint?  
   
  
  - var client = new 
ServiceReference1.Service1Client();      
  
  - var client = new 
ServiceReference1.Service1Client();   
 
 
引用WCF服务2:在CS文件中,直接定义WCF服务,代码如下:
 
 
 
  
  
  - view plaincopy to clipboardprint?  
   
  
  - Binding binding = 
new BasicHttpBinding();      
  
  - EndpointAddress endPoint = 
new EndpointAddress(      
  
  - "http://localhost:2442/Service1.svc");   
   
  
  - Service1Client client =
 new Service1Client(binding, endPoint);      
  
  - Binding binding = 
new BasicHttpBinding();     
  
  - EndpointAddress endPoint = 
new EndpointAddress(     
  
  - "http://localhost:2442/Service1.svc");  
   
  
  - Service1Client client = 
new Service1Client(binding, endPoint);    
 
 
以上两种引用WCF服务方式都能设用WCF服务,比如第一种方式,如果没有定义配置文件,则会报 找不到键值的错误提示.
            
            新闻标题:引用WCF服务经验分享            
            当前地址:
http://zsjierui.cn/article/cdcjppj.html