我遇到一个问题,我试图从WCF服务中传输大量对象。我必须将对象的传输限制为100,否则会出现某种通信错误。
我尝试了解决方案中的建议,在这里找到了,但也许我遗漏了什么,因为我仍然会出错。
以下是我的WCF服务web.config的底部:
<system.web>
<httpRuntime maxRequestLength="102400" />
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="MyWsHttpBinding" />
</wsHttpBinding>
<netTcpBinding>
<binding name="myNetTcpBinding"
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="524288"
maxConnections="10"
maxReceivedMessageSize="2147483647">
<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" />
</security>
</binding>
</netTcpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="myNetTcpBehaviour">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="myNetTcpEndPointBehaviour">
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
接下来,这里是使用web服务的网站的web.config部分的下部:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IFeederService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="2147483647" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="55000" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="myEndPointBehavior">
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
</endpointBehaviors>
</behaviors>
<client>
<endpoint address="http://www.mysiate.com/MyService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IFeederService"
contract="FeederService.IFeederService" name="BasicHttpBinding_IFeederService" />
</client> </system.serviceModel>
我得到的错误是:
接收对的HTTP响应时出错http://www.mysite.com/MyService.svc.这可能是由于服务未使用HTTP协议的端点绑定。这也可能是由于由于HTTP请求上下文被服务器中止(可能是由于到服务关闭)。有关详细信息,请参阅服务器日志。
奇怪的是,当我写这篇文章时,我将返回逻辑更改为190个对象,并进行了重试,结果成功了。重试,但失败了。
这可能是更改某些IIS设置的问题吗?
如有任何协助,我们将不胜感激。
谢谢。
错误消息显示:
有关详细信息,请参阅服务器日志。
我将首先在服务器上配置跟踪,如MSDN文章中所述。
您在服务配置中没有声明任何端点,这意味着WCF默认端点模型正在使用
但是,您已经命名了绑定配置和行为,这意味着它们不会被默认端点获取。如果从绑定配置和行为中删除这些名称,则它们将成为默认设置,并由默认端点
您不能使用'Streamed'WCF绑定吗?
WCF;流式
您的绑定需要将behaviourconfiguration设置为您的行为。
<endpoint address="http://www.mysiate.com/MyService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IFeederService"
behaviorConfiguration="myEndPointBehavior" contract="FeederService.IFeederService" name="BasicHttpBinding_IFeederService" />
</client> </system.serviceModel>
否则,将不会使用图形设置