gpt4 book ai didi

c# - WCF 服务调用失败...我的配置文件有什么问题?

转载 作者:太空宇宙 更新时间:2023-11-03 14:05:35 24 4
gpt4 key购买 nike

我有一个 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>

这些看起来正确吗?如果是这样,我在其中任何一个中是否缺少任何可以使这项工作成功的东西?

谢谢

最佳答案

明白了……终于明白了。问题是在服务器端 web.config 上,行为 maxItemsInObjectGraph 必须是服务行为,而不是端点行为。

关于c# - WCF 服务调用失败...我的配置文件有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9398434/

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