WCF netTcp配置

  1. 服务端配置  
  2. <system.serviceModel>  
  3.     <bindings>  
  4.       <netTcpBinding>  
  5.         <binding name="netTcpExpenseService_ForSupplier" closeTimeout="00:01:00"  
  6.             openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"  
  7.             transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"  
  8.             hostNameComparisonMode="StrongWildcard" listenBacklog="10"  
  9.             maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxConnections="10"  
  10.             maxReceivedMessageSize="2147483647">  
  11.           <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647"  
  12.               maxBytesPerRead="4096" maxNameTableCharCount="16384" />  
  13.           <reliableSession ordered="true" inactivityTimeout="00:10:00"  
  14.               enabled="false" />  
  15.           <security mode="None">  
  16.             <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />  
  17.             <message clientCredentialType="Windows" />  
  18.           </security>  
  19.         </binding>  
  20.       </netTcpBinding>  
  21.   
  22.     </bindings>  
  23.     <services>  
  24.       <!--联系人服务-->  
  25.       <service name="Service.Implement.Travel.Supplyer.Contact_Service">  
  26.         <endpoint address="net.tcp://10.1.3.203:9999/Service.Implement.Travel.Supplyer.Contact_Service"  
  27.            contract="Service.Interface.Travel.Supplyer.Contact_IService"  
  28.              binding="netTcpBinding" bindingConfiguration="netTcpExpenseService_ForSupplier"/>  
  29.       </service>  
  30.   
  31.     </services>  
  32.     <behaviors>  
  33.       <serviceBehaviors>  
  34.         <behavior name="MyServiceTypeBehaviors" >  
  35.   
  36.           <serviceMetadata httpGetEnabled="true" />  
  37.         </behavior>  
  38.       </serviceBehaviors>  
  39.     </behaviors>  
  40.   
  41.   </system.serviceModel>  
  42.   
  43.   
  44. 1,<security mode="Transport">  安全性修改   <security mode="None">  
  45. 2,绑定监听配置 bindingConfiguration="netTcpExpenseService_ForSupplier"   
  46. 3,服务端设置<services>节点  
  47.   
  48.   
  49.   
  50. 客户端配置  
  51.   <system.serviceModel>  
  52.     <bindings>  
  53.       <netTcpBinding>  
  54.         <binding name="netTcpExpenseService_ForSupplier" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"            
  55.   
  56. transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions" hostNameComparisonMode="StrongWildcard" listenBacklog="10"             
  57.   
  58. maxBufferPoolSize="20000000" maxBufferSize="20000000" maxConnections="10" maxReceivedMessageSize="2147483647">  
  59.           <readerQuotas maxDepth="32" maxStringContentLength="8192000" maxArrayLength="8192000" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>  
  60.           <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false"/>  
  61.           <security mode="None">  
  62.             <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign"/>  
  63.             <message clientCredentialType="Windows"/>  
  64.           </security>  
  65.         </binding>  
  66.       </netTcpBinding>  
  67.     </bindings>  
  68.     <client>  
  69.     <endpoint name="ContactService" address="net.tcp://10.1.3.203:9999/Service.Implement.Travel.Supplyer.Contact_Service"            
  70.   
  71. contract="Service.Interface.Travel.Supplyer.Contact_IService" binding="netTcpBinding" bindingConfiguration="netTcpExpenseService_ForSupplier"/>  
  72.     </client>  
  73.   </system.serviceModel>  
  74.   
  75. 1,<security mode="Transport">  安全性修改   <security mode="None">  
  76. 2,绑定监听配置 bindingConfiguration="netTcpExpenseService_ForSupplier"   
  77. 3,客户端设置 <client>节点  
  78.   
  79. 总结:监听协议,服务端和客户端netTcpBinding节点配置保持一致.  
  80.   
  81.   
  82. 调用wcf接口  
  83.                 Contact_IService iwt = WCFClientProxy<Contact_IService>.GetReusableFaultUnwrappingInstance("ContactService");  
  84.                 Contact model = new Contact();  
  85.                 model.SupplierID = 4706;  
  86.                 model.ContactType = 1;  
  87.                 List<Contact> list = iwt.GetContactList(model);  
  88.                 var query = list.Take(1).ToList();//默认取第一个  
  89.                 string tel = string.Empty;  
  90.                 string fax = string.Empty;  
  91.                 foreach (var item in query)  
  92.                 {  
  93.                     tel = item.ContactPhone;  
  94.                     fax = item.ContactFax;  
  95.                 }  
  96.                 Response.Write("电话:" + tel + "\n" + "传真:" + fax); 

你可能感兴趣的:(WCF)