自己通过编写WCF服务端,在客户端直接添加服务引用时发现不能引用对netTcpBinding直接引用(net.tcp://127.0.0.1:8081),所以自己找到方法了记录以备不时之需。
服务端配置:
<?xml version="1.0" encoding="utf-8" ?> <configuration> <system.serviceModel> <behaviors> <serviceBehaviors> <behavior name="mexConfig"> <serviceMetadata httpGetEnabled="true" httpGetUrl="http://120.25.160.17:8080/" /> <serviceDebug includeExceptionDetailInFaults="true" /> </behavior> </serviceBehaviors> </behaviors> <bindings> <netTcpBinding> <binding name="MyTcpBinding" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" sendTimeout="00:30:00" transferMode="Streamed" > <security mode="None"></security> </binding> </netTcpBinding> </bindings> <services> <service behaviorConfiguration="mexConfig" name="WCFService.Service"> <endpoint address="net.tcp://120.25.160.17:8081/" binding="netTcpBinding" bindingConfiguration="MyTcpBinding" contract="WCFService.IService" /> <endpoint address="net.tcp://120.25.160.17:8081/" binding="netTcpBinding" bindingConfiguration="MyTcpBinding" contract="WCFService.IMyName" /> <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" /> <host> <baseAddresses> <add baseAddress="net.tcp://120.25.160.17:8081/" /> </baseAddresses> </host> </service> </services> </system.serviceModel> </configuration>
客服端配置:
<?xml version="1.0" encoding="utf-8"?> <configuration> <system.serviceModel> <bindings> <netTcpBinding> <binding name="NetTcpBinding_IService" transferMode="Streamed"> <security mode="None" /> </binding> <binding name="NetTcpBinding_IMyName" transferMode="Streamed"> <security mode="None" /> </binding> </netTcpBinding> </bindings> <client> <endpoint address="net.tcp://120.25.160.17:8081/" binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IService" contract="wcf.IService" name="NetTcpBinding_IService" /> <endpoint address="net.tcp://120.25.160.17:8081/" binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IMyName" contract="wcf.IMyName" name="NetTcpBinding_IMyName" /> </client> </system.serviceModel> </configuration>
时间: 2024-11-07 15:56:42