简体   繁体   English

WCF服务-与消息/对象大小有关

[英]WCF Service - Message / Object size related

I have wcf service (S1) as client and another Wcf service(S2) as server. 我将wcf服务(S1)作为客户端,将另一个Wcf服务(S2)作为服务器。 S1 consume S2 over net.tcp. S1通过net.tcp消耗S2。 S2 has one operation, which return a complex object with most of it's contents are string. S2有一个操作,它返回一个复杂的对象,其中大部分内容都是字符串。 The average size of this object is between 7-8 MB. 该对象的平均大小在7-8 MB之间。

Recently I had to add more string contents to the actual object graph. 最近,我不得不在实际的对象图中添加更多的字符串内容。 This cause S2 to return following error 这导致S2返回以下错误

The socket connection was aborted. 套接字连接已中止。 This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. 这可能是由于处理您的消息时出错,远程主机超出了接收超时或潜在的网络资源问题引起的。 Local socket timeout was '00:05:00'. 本地套接字超时为“ 00:05:00”。 System.Net.Sockets.SocketException (0x80004005): An existing connection was forcibly closed by the remote host at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags) at System.ServiceModel.Channels.SocketConnection.ReadCore(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout, Boolean closing) System.Net.Sockets.SocketException(0x80004005):System.Net.Sockets.Socket.Receive(Byte []缓冲区,Int32偏移量,Int32大小,SocketFlags socketFlags)处的远程主机强行关闭了现有连接。 .Channels.SocketConnection.ReadCore(Byte []缓冲区,Int32偏移量,Int32大小,TimeSpan超时,布尔值关闭)

However, everything works as expected when I remove some of the string contents from the object graph. 但是,当我从对象图中删除一些字符串内容时,一切都按预期工作。

After doing bit of a homework,I was managed to land on a conclusion that, it has something to do with the size of the returned object. 在做完一些作业之后,我设法得出一个结论,即它与返回对象的大小有关。 This made me to revise my client and service configuration/quota's. 这使我可以修改客户端和服务配置/配额。

However, I have no luck even after modifying the client and service especially size related attributes. 但是,即使修改了客户端和服务,尤其是与大小相关的属性,我也没有运气。

Can someone guide me on this? 有人可以指导我吗? Please ask me for more information if needed. 如果需要,请询问我更多信息。

Thanks in advance. 提前致谢。

Client (S1) 客户(S1)

<netTcpBinding>
        <binding name="NetTcp" closeTimeout="00:05:00"
          openTimeout="00:05:00" receiveTimeout="00:10:00" sendTimeout="00:05:00"
          transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
          hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="2147483647"
          maxBufferSize="2147483647" maxConnections="10" maxReceivedMessageSize="2147483647">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
            maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="16384" />
          <reliableSession ordered="true" inactivityTimeout="00:10:00"
            enabled="false" />
          <security mode="None">
            <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
            <message clientCredentialType="Windows" />
          </security>
        </binding>
      </netTcpBinding>
    <client>
          <endpoint address="net.tcp://xxxxxxxx/xxxxxxService"
            binding="netTcpBinding" bindingConfiguration="NetTcp" behaviorConfiguration="RBehavior"  
            contract="IService" name="NetTcp" />
        </client>
        <services/>

        <behaviors>
          <serviceBehaviors>
            <behavior name="NSBehavior">
              <etwTracking profileName="EndToEndMonitoringProfile"/>
              <serviceMetadata httpGetEnabled="false"/>
              <serviceDebug includeExceptionDetailInFaults="true"/>
            </behavior> 

          </serviceBehaviors>
        <endpointBehaviors>                                   
                <behavior name="RBehavior">
     **<dataContractSerializer maxItemsInObjectGraph="2147483647" />**
                </behavior>
            </endpointBehaviors>
        </behaviors>

        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
      </system.serviceModel>

     <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"/>
      </system.webServer>

Server (S2) 服务器(S2)

<system.serviceModel>
    <bindings>
      <netTcpBinding>
        <binding name="netTcp" closeTimeout="00:03:00"
          openTimeout="00:03:00" receiveTimeout="00:10:00" sendTimeout="00:03:00"
          transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
          hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="20000000"
          maxBufferSize="20000000" maxConnections="10" maxReceivedMessageSize="20000000">
          <readerQuotas maxDepth="32" maxStringContentLength="20000000"
            maxArrayLength="20000000" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <reliableSession ordered="true" inactivityTimeout="00:10:00"
            enabled="false" />
          <security mode="None">
            <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
            <message clientCredentialType="Windows" />
          </security>
        </binding>
      </netTcpBinding>
    </bindings>

    <services>
      <service name="Engine.Rules"
               behaviorConfiguration="REServiceBehavior">
        <host>
          <baseAddresses>
            <add baseAddress="net.tcp://xxxxx:8005/Service"/>
          </baseAddresses>
        </host>
        <endpoint address=""
                  binding="netTcpBinding" bindingConfiguration="netTcp"
                  contract="Ixxxx" />
        <endpoint address="mex"
                  binding="mexTcpBinding"
                  contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="REServiceBehavior">
          <serviceMetadata httpGetEnabled="false"/>
      **<dataContractSerializer maxItemsInObjectGraph="2147483647"/>**
          <serviceDebug includeExceptionDetailInFaults="true"/>  
          <serviceThrottling maxConcurrentSessions="1000"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

Update : As per @ErikFunkenbusch's sensible support, I am attaching service trace information. 更新 :根据@ErikFunkenbusch的明智支持,我附上了服务跟踪信息。 例外

<ExceptionString>System.ServiceModel.CommunicationException: The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '00:05:00'. ---&gt; System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
   at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
   at System.ServiceModel.Channels.SocketConnection.ReadCore(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout, Boolean closing)
   --- End of inner exception stack trace ---</ExceptionString>
<InnerException>
<ExceptionType>System.Net.Sockets.SocketException, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType>
<Message>An existing connection was forcibly closed by the remote host</Message>
<StackTrace>
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at System.ServiceModel.Channels.SocketConnection.ReadCore(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout, Boolean closing)
</StackTrace>
<ExceptionString>System.Net.Sockets.SocketException (0x80004005): An existing connection was forcibly closed by the remote host
   at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
   at System.ServiceModel.Channels.SocketConnection.ReadCore(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout, Boolean closing)</ExceptionString>
<NativeErrorCode>2746</NativeErrorCode>
</InnerException>
</Exception>

Have you tried increasing the send and receive timeout values? 您是否尝试过增加发送和接收超时值? You're sending a lot of data over the wire (7-8MB) and 5 seconds may not be enough time to complete that transaction. 您正在通过网络发送大量数据(7-8MB),而5秒的时间可能不足以完成该事务。 Try setting them to something like 30 seconds and then working from there. 尝试将它们设置为30秒左右,然后从那里开始工作。

E: E:

<binding name="netTcp" closeTimeout="00:30:00"
      openTimeout="00:30:00" receiveTimeout="00:30:00" sendTimeout="00:30:00">

That is what I'm referring to, specifically. 这就是我要特别指的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM