gpt4 book ai didi

c# - WCF 错误 "The socket connection has been disposed"

转载 作者:行者123 更新时间:2023-11-30 17:59:29 25 4
gpt4 key购买 nike

我有一个 WCF 服务,可以根据输入参数返回大量数据。

该服务作为 ServiceHost 可执行文件在我的机器上运行,我现在正在使用 WCF 测试客户端进行测试。

这是我的主机配置:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="NetTcpBinding_ExchangeRepository"
closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:10:00"
transactionFlow="false" transferMode="Streamed"
transactionProtocol="OleTransactions" hostNameComparisonMode="StrongWildcard"
listenBacklog="500" maxBufferPoolSize="2147483646"
maxBufferSize="2147483646" maxConnections="500"
maxReceivedMessageSize="2147483647" >
<readerQuotas
maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647"
maxBytesPerRead="4096" maxNameTableCharCount="2147483647" />
<reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" />
<security mode="None">
</security>
</binding>
</netTcpBinding>
</bindings>
<services>
<service name="MyCompany.MyApplication.DataServices.ExchangeRepository"
behaviorConfiguration="MyCompany.MyApplication.DataServicesBehavior">
<endpoint address =""
binding="netTcpBinding"
contract="MyCompany.MyApplication.DataServices.IExchangeRepository"
bindingConfiguration="NetTcpBinding_ExchangeRepository"
behaviorConfiguration="MyCompany.MyApplication.EndpointBehavior">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress = "net.tcp://localhost:8896/ExchangeRepository/" />
<add baseAddress = "http://localhost:8895/ExchangeRepository/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyCompany.MyApplication.DataServicesBehavior">
<dataContractSerializer maxItemsInObjectGraph="2147483646"/>
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="True" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="MyCompany.MyApplication.EndpointBehavior">
<dataContractSerializer maxItemsInObjectGraph="2147483646"/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
</configuration>

这是我的客户端配置:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="endpointBehaviour">
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<netTcpBinding>
<binding name="NetTcpBinding_IExchangeRepository" closeTimeout="00:10:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
transactionFlow="false" transferMode="Streamed" transactionProtocol="OleTransactions"
hostNameComparisonMode="StrongWildcard" listenBacklog="10"
maxBufferPoolSize="524288" maxBufferSize="2147483647" maxConnections="10"
maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="32" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="4096" maxNameTableCharCount="2147483647" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="None">
<transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
<message clientCredentialType="Windows" />
</security>
</binding>
</netTcpBinding>
</bindings>
<client>
<endpoint address="net.tcp://localhost:8896/ExchangeRepository/"
behaviorConfiguration="endpointBehaviour" binding="netTcpBinding"
bindingConfiguration="NetTcpBinding_IExchangeRepository" contract="IExchangeRepository"
name="NetTcpBinding_IExchangeRepository">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>

这是我得到的错误:

The socket connection has been disposed.

Server stack trace:
at System.ServiceModel.Channels.SocketConnection.ThrowIfNotOpen()
at System.ServiceModel.Channels.SocketConnection.Read(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout)
at System.ServiceModel.Channels.DelegatingConnection.Read(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout)
at System.ServiceModel.Channels.PreReadConnection.Read(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout)
at System.ServiceModel.Channels.SingletonConnectionReader.SingletonInputConnectionStream.ReadCore(Byte[] buffer, Int32 offset, Int32 count)
at System.ServiceModel.Channels.SingletonConnectionReader.SingletonInputConnectionStream.Read(Byte[] buffer, Int32 offset, Int32 count)
at System.ServiceModel.Channels.MaxMessageSizeStream.Read(Byte[] buffer, Int32 offset, Int32 count)
at System.ServiceModel.Channels.SingletonConnectionReader.Close(TimeSpan timeout)
at System.ServiceModel.Channels.SingletonConnectionReader.SingletonInputConnectionStream.Close()
at System.ServiceModel.Channels.DelegatingStream.Close()
at System.Xml.XmlBufferReader.Close()
at System.Xml.XmlBaseReader.Close()
at System.Xml.XmlBinaryReader.Close()
at System.Xml.XmlReader.Dispose(Boolean disposing)
at System.Xml.XmlReader.Dispose()
at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeBodyContents(Message message, Object[] parameters, Boolean isRequest)
at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeReply(Message message, Object[] parameters)
at System.ServiceModel.Dispatcher.ProxyOperationRuntime.AfterReply(ProxyRpc& rpc)
at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at IExchangeRepository.SearchExchangeRequest(String AccountNumber, Int32 StatusCode, Int32 StartDate, Int32 EndDate)
at ExchangeRepositoryClient.SearchExchangeRequest(String AccountNumber, Int32 StatusCode, Int32 StartDate, Int32 EndDate)

Inner Exception:
The socket connection has been disposed.
Object name: 'System.ServiceModel.Channels.SocketConnection'.

当返回的数据多于一定数量的记录时会发生错误。使用较少的数据,一切都按预期工作。

关于如何解决这个问题有什么建议吗?

最佳答案

这一切都是由愚蠢的数据问题引起的。错误信息是绝对没有用的。启用跟踪允许查看实际异常。谢谢你,EkoostikMartin!

关于c# - WCF 错误 "The socket connection has been disposed",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11162190/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com