簡體   English   中英

WCF服務-與消息/對象大小有關

[英]WCF Service - Message / Object size related

我將wcf服務(S1)作為客戶端,將另一個Wcf服務(S2)作為服務器。 S1通過net.tcp消耗S2。 S2有一個操作,它返回一個復雜的對象,其中大部分內容都是字符串。 該對象的平均大小在7-8 MB之間。

最近,我不得不在實際的對象圖中添加更多的字符串內容。 這導致S2返回以下錯誤

套接字連接已中止。 這可能是由於處理您的消息時出錯,遠程主機超出了接收超時或潛在的網絡資源問題引起的。 本地套接字超時為“ 00:05:00”。 System.Net.Sockets.SocketException(0x80004005):System.Net.Sockets.Socket.Receive(Byte []緩沖區,Int32偏移量,Int32大小,SocketFlags socketFlags)處的遠程主機強行關閉了現有連接。 .Channels.SocketConnection.ReadCore(Byte []緩沖區,Int32偏移量,Int32大小,TimeSpan超時,布爾值關閉)

但是,當我從對象圖中刪除一些字符串內容時,一切都按預期工作。

在做完一些作業之后,我設法得出一個結論,即它與返回對象的大小有關。 這使我可以修改客戶端和服務配置/配額。

但是,即使修改了客戶端和服務,尤其是與大小相關的屬性,我也沒有運氣。

有人可以指導我嗎? 如果需要,請詢問我更多信息。

提前致謝。

客戶(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>

服務器(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>

更新 :根據@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>

您是否嘗試過增加發送和接收超時值? 您正在通過網絡發送大量數據(7-8MB),而5秒的時間可能不足以完成該事務。 嘗試將它們設置為30秒左右,然后從那里開始工作。

E:

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

這就是我要特別指的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM