【发布时间】:2012-02-22 16:05:40
【问题描述】:
我有一个 C# WCF 服务,它将一组实例化的 .Net 对象传递给调用者。工作正常,但是如果我尝试在集合中传递太多对象,则会失败并出现以下异常:
{"An error occurred while receiving the HTTP response to http://myserver/MyAppService/MyAppService.svc. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details."}
{"The underlying connection was closed: An unexpected error occurred on a receive."}
{"Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host."}
{"An existing connection was forcibly closed by the remote host"}
它是完全可复制的,并且肯定与集合中的对象数量有关,而不是对象的内容。
根据我发表的另一篇文章,我尝试对客户端 app.config 文件和服务服务器端 web.config 文件进行更改。但是这些更改并没有解决问题,这让我认为我可能没有正确设置我的配置文件。
以下是我的客户端 app.config 文件(不相关的内容已删除):
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_iMyAppService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="01:00:00" sendTimeout="01:00:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="2147483647" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647"
maxBytesPerRead="4096" maxNameTableCharCount="2147483647" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="Behaviors.EndpointBehavior">
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
</endpointBehaviors>
</behaviors>
<client>
<endpoint address="http://myserver/MyAppService/MyAppService.svc"
behaviorConfiguration="Behaviors.EndpointBehavior"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_iMyAppService"
contract="MyAppService.iMyAppService" name="BasicHttpBinding_iMyAppService" />
</client>
</system.serviceModel>
这是我的服务器端 web.config 文件(不相关的内容已删除):
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="Behaviors.EndpointBehavior">
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_iMyAppService"
closeTimeout="00:01:00"
openTimeout="01:00:00" receiveTimeout="01:00:00" sendTimeout="01:00:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="2147483647" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647"
maxBytesPerRead="4096" maxNameTableCharCount="2147483647" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
<services>
<service name="MyApp_WCFService.MyAppService">
<host>
<baseAddresses>
<add baseAddress="http://localhost/MyAppService/"/>
</baseAddresses>
</host>
<endpoint address="" behaviorConfiguration="Behaviors.EndpointBehavior" binding="basicHttpBinding" contract="MyApp_WCFService.iMyAppService" bindingConfiguration="BasicHttpBinding_iMyAppService">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
</modules>
</system.webServer>
这些看起来正确吗?如果是这样,我在其中任何一个中都缺少什么可以使这项工作正常进行吗?
谢谢
【问题讨论】:
-
您是在使用 WCF 服务配置编辑器,还是在手动修改这些文件?
-
我在自动创建文件后手动修改了它们。配置编辑器在简单的 .config 文件上给出错误,无需任何修改。
-
其他人看到有什么问题吗?
-
我建议使用配置编辑器使配置没有错误。正如您所说,我没有遇到基本配置文件有错误的问题。我还会检查服务器上的事件日志以获取更多上下文。最后,尝试在客户端和服务器上设置一个 WSHttpBinding 并使用它来代替 Basic。
标签: c# wpf wcf web-services