新聞中心
這里有您想知道的互聯網營銷解決方案
引用WCF服務正確實現方法介紹
當我們在實際編程中需要對WCF服務進行引用的時候,需要兩種方法來實現。那么今天我們就針對引用WCF服務的相關方法來進行一個詳細介紹。希望這里介紹的內容可以解決朋友在實際應用中碰到的問題。

創(chuàng)新互聯是一家專業(yè)提供孟村企業(yè)網站建設,專注與成都做網站、成都網站設計、HTML5、小程序制作等業(yè)務。10年已為孟村眾多企業(yè)、政府機構等服務。創(chuàng)新互聯專業(yè)網絡公司優(yōu)惠進行中。
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>
- < 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();
- 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);
- Binding binding = new BasicHttpBinding();
- EndpointAddress endPoint = new EndpointAddress(
- "http://localhost:2442/Service1.svc");
- Service1Client client = new Service1Client(binding, endPoint);
以上兩種方式都能引用WCF服務,比如***種方式,如果沒有定義配置文件,則會報 找不到鍵值的錯誤提示.
【編輯推薦】
- 兩個基本WCF應用技巧總結
- WCF擴展點在自定義運行時使用
- WCF客戶端具體搭建方法解析
- WCF IDisposable接口應用功能詳解
- WCF REST正確定義方法介紹
當前標題:引用WCF服務正確實現方法介紹
文章起源:http://www.5511xx.com/article/dpoigeh.html


咨詢
建站咨詢
