我在启动和运行NetTcpBinding连接时遇到问题。我能够获得Http绑定和命名管道绑定工作但是Tcp给了我很大的麻烦。到目前为止,我尝试了许多不同的东西,但没有一个有效。
我已经读过,问题可能在于客户端绑定的最大缓冲区大小,我将maxBufferPoolSize,maxBufferSize和maxReceivedMessageSize提升到最大值。那没有效果。我已经读过这个问题可能是端口共享所以我在我的机器上启用了端口共享,但这也没有效果。我还禁用了机器上的防火墙,但这也没有改变任何东西。
我得到的确切错误是:
CommunicationException
套接字连接已中止。这可能是由错误引起的 处理您的消息或超过接收超时 远程主机或底层网络资源问题。本地套接字 超时为'00:00:59.8127832'。
据我所知,当WCF并不确切知道出了什么问题时,这是一种全面的例外。
我不知道接下来应该尝试什么。我希望你能提供帮助。
这是服务器配置
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="DummyServer.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="MetaDataBehavior">
<serviceMetadata/>
<serviceDebug />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="MetaDataBehavior" name="DummyServiceLibrary.DummyServiceA">
<endpoint binding="basicHttpBinding"
contract="DummyServiceLibrary.IDummyService" />
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
<endpoint binding="netTcpBinding"
contract="DummyServiceLibrary.IDummyService" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/dummy" />
<add baseAddress="net.tcp://localhost:8523/dummy" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
<applicationSettings>
<DummyServer.Properties.Settings>
<setting name="ServiceType" serializeAs="String">
<value>A</value>
</setting>
</DummyServer.Properties.Settings>
</applicationSettings>
</configuration>
这是客户端配置
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="DummyClient.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IDummyService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
<netTcpBinding>
<binding name="NetTcpBinding_IDummyService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
hostNameComparisonMode="StrongWildcard" listenBacklog="10"
maxBufferPoolSize="2147483647" maxBufferSize="2147483647"
maxConnections="10" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None" />
</binding>
</netTcpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8080/dummy" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IDummyService" contract="DummyService.IDummyService"
name="BasicHttpBinding_IDummyService" />
<endpoint address="net.tcp://localhost:8523/dummy" binding="netTcpBinding"
bindingConfiguration="NetTcpBinding_IDummyService" contract="DummyService.IDummyService"
name="NetTcpBinding_IDummyService" />
</client>
</system.serviceModel>
<applicationSettings>
<DummyClient.Properties.Settings>
<setting name="ClientEndPoint" serializeAs="String">
<value>NetTcpBinding_IDummyService</value>
</setting>
</DummyClient.Properties.Settings>
</applicationSettings>
</configuration>
我希望你能找到我无法找到的东西。
编辑#1 通过定义DNS,我已经能够启动并运行TCP端点。
这是新的服务器端点定义。
<endpoint binding="netTcpBinding" contract="DummyServiceLibrary.IDummyService">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
这是新的客户端绑定定义和客户端端点定义。
<netTcpBinding>
<binding name="NetTcpBinding_IDummyService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
hostNameComparisonMode="StrongWildcard" listenBacklog="10"
maxBufferPoolSize="524288" maxBufferSize="65536" maxConnections="10"
maxReceivedMessageSize="65536">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Transport">
<transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
<message clientCredentialType="Windows" />
</security>
</binding>
</netTcpBinding>
<endpoint address="net.tcp://localhost:8523/dummy" binding="netTcpBinding"
bindingConfiguration="NetTcpBinding_IDummyService" contract="DummyService.IDummyService"
name="NetTcpBinding_IDummyService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>