WCF服务 - 留言/对象大小相关 [英] WCF Service - Message / Object size related

查看:202
本文介绍了WCF服务 - 留言/对象大小相关的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有WCF服务(S1)客户端和另一个WCF服务(S2)作为服务器。 S1 S2消耗过的net.tcp。 S2有一个操作,它返回一个复杂的对象,大部分的内容是字符串。此对象的平均大小介于7-8 MB

最近我有更多的字符串内容添加到实际的对象图。这导致S2返回以下错误

  

套接字连接被中止。这可能是由错误引起的   处理您的信息或接收超时而被超过了   远程主机,或者潜在的网络资源问题。本地套接字   超时是'00:05:00'。 System.Net.Sockets.SocketException   (0X80004005):一个现有的连接被强行远程关闭   主机在System.Net.Sockets.Socket.Receive(字节[]缓冲区的Int32   偏移的Int32大小的SocketFlags的SocketFlags)在   System.ServiceModel.Channels.SocketConnection.ReadCore(字节[]缓冲区,   INT32偏移,INT32大小,时间跨度超时,布尔关)

然而,一切都将按预期如果我删除了一些字符串内容从对象图。

做了功课一点后,我设法土地上,它是与返回的对象大小的结论。这让我修改我的客户和服务配置/配额的。

不过,我甚至修改客户端和服务尤其是大小相关的属性后,没有运气。

有人能指导我一下吗?请问我是否需要更多的信息。

在此先感谢。

客户端(S1)

 < NetTcpBinding的>
        <绑定名称=NetTcpcloseTimeout =00:05:00
          openTimeout =00:05:00receiveTimeout =00:10:00的SendTimeout =00:05:00
          transactionFlow =假transferMode =缓冲transactionProtocol =OleTransactions
          hostNameComparisonMode =StrongWildcard将ListenBackLog =10maxBufferPoolSize =2147483647
          maxBufferSize =2147483647MAXCONNECTIONS =10maxReceivedMessageSize =2147483647>
          < readerQuotas MAXDEPTH =2147483647maxStringContentLength =2147483647
            maxArrayLength =2147483647maxBytesPerRead =2147483647maxNameTableCharCount =16384/>
          <有序的ReliableSession =真正的inactivityTimeout =00:10:00
            启用=FALSE/>
          <安全模式=无>
            <交通运输clientCredentialType =窗口的ProtectionLevel =EncryptAndSign/>
            <消息clientCredentialType =的Windows/>
          < /安全>
        < /装订>
      < / NetTcpBinding的>
    <客户端>
          <端点地址=的net.tcp:// XXXXXXXX / xxxxxxService
            绑定=NetTcpBinding的bindingConfiguration =NetTcpbehaviorConfiguration =RBehavior
            合同=IServiceNAME =NetTcp/>
        < /客户>
        <服务/>

        <行为>
          < serviceBehaviors>
            <行为NAME =NSBehavior>
              < etwTracking PROFILENAME =EndToEndMonitoringProfile/>
              < serviceMetadata httpGetEnabled =FALSE/>
              < serviceDebug includeExceptionDetailInFaults =真/>
            < /行为>

          < / serviceBehaviors>
        < endpointBehaviors>
                <行为NAME =RBehavior>
     **< D​​ataContractSerializer的maxItemsInObjectGraph =2147483647/> **
                < /行为>
            < / endpointBehaviors>
        < /行为>

        < serviceHostingEnvironment multipleSiteBindingsEnabled =真/>
      < /system.serviceModel>

     < system.webServer>
        <模块runAllManagedModulesForAllRequests =真/>
      < /system.webServer>
 

服务器(S2)

 < system.serviceModel>
    <绑定>
      < NetTcpBinding的>
        <绑定名称=netTcpcloseTimeout =00:03:00
          openTimeout =00:03:00receiveTimeout =00:10:00的SendTimeout =00:03:00
          transactionFlow =假transferMode =缓冲transactionProtocol =OleTransactions
          hostNameComparisonMode =StrongWildcard将ListenBackLog =10maxBufferPoolSize =20000000
          maxBufferSize =20000000MAXCONNECTIONS =10maxReceivedMessageSize =20000000>
          < readerQuotas MAXDEPTH =32maxStringContentLength =20000000
            maxArrayLength =20000000maxBytesPerRead =4096maxNameTableCharCount =16384/>
          <有序的ReliableSession =真正的inactivityTimeout =00:10:00
            启用=FALSE/>
          <安全模式=无>
            <交通运输clientCredentialType =窗口的ProtectionLevel =EncryptAndSign/>
            <消息clientCredentialType =的Windows/>
          < /安全>
        < /装订>
      < / NetTcpBinding的>
    < /绑定>

    <服务>
      <服务名称=Engine.Rules
               behaviorConfiguration =REServiceBehavior>
        <主机>
          < baseAddresses>
            <新增baseAddress =的net.tcp:// XXXXX:8005 /服务/>
          < / baseAddresses>
        < /主机>
        <端点地址=
                  绑定=NetTcpBinding的bindingConfiguration =netTcp
                  合同=Ixxxx/>
        <端点地址=MEX
                  绑定=mexTcpBinding
                  合同=IMetadataExchange接口/>
      < /服务>
    < /服务>
    <行为>
      < serviceBehaviors>
        <行为NAME =REServiceBehavior>
          < serviceMetadata httpGetEnabled =FALSE/>
      **< D​​ataContractSerializer的maxItemsInObjectGraph =2147483647/> **
          < serviceDebug includeExceptionDetailInFaults =真/>
          < serviceThrottling maxConcurrentSessions =1000/>
        < /行为>
      < / serviceBehaviors>
    < /行为>
  < /system.serviceModel>
 

更新:按@ ErikFunkenbusch的明智的支持,我附上服务跟踪信息

 < ExceptionString> System.ServiceModel.CommunicationException:套接字连接被中止。这可能是一个错误处理您的信息或接收超时导致被超过的远程主机,或者潜在的网络资源问题。本地套接字超时是00:05:00。 ---与放大器; GT; System.Net.Sockets.SocketException:一个现有的连接被强行关闭远程主机
   在System.Net.Sockets.Socket.Receive(字节[]缓冲区的Int32偏移的Int32大小的SocketFlags的SocketFlags)
   在System.ServiceModel.Channels.SocketConnection.ReadCore(字节[]缓冲区的Int32偏移的Int32规模,时间跨度超时,布尔收盘)
   ---内部异常堆栈跟踪---&LT结束; / ExceptionString>
<的InnerException>
< ExceptionType> System.Net.Sockets.SocketException,系统,版本= 4.0.0.0,文化=中性公钥= b77a5c561934e089< / ExceptionType>
<消息>一种现有的连接被强行远程主机&LT封闭; /消息>
<堆栈跟踪>
在System.Net.Sockets.Socket.Receive(字节[]缓冲区的Int32偏移的Int32大小的SocketFlags的SocketFlags)
在System.ServiceModel.Channels.SocketConnection.ReadCore(字节[]缓冲区的Int32偏移的Int32规模,时间跨度超时,布尔收盘)
< /堆栈跟踪>
< ExceptionString> System.Net.Sockets.SocketException(0X80004005):一个现有的连接被强行关闭远程主机
   在System.Net.Sockets.Socket.Receive(字节[]缓冲区的Int32偏移的Int32大小的SocketFlags的SocketFlags)
   在System.ServiceModel.Channels.SocketConnection.ReadCore(字节[]缓冲区的Int32偏移的Int32规模,时间跨度超时,布尔收盘)LT; / ExceptionString>
< NativeError code> 2746< / NativeError code取代;
< /的InnerException>
< /异常>
 

解决方案

您是否尝试过增加了发送和接收超时值?你发送大量的数据通过有线(7-8MB),并在5秒可能没有足够的时间来完成该交易。尽量将它们设置为像30秒,然后从那里工作。

E:

 <绑定名称=netTcpcloseTimeout =00:30:00
      openTimeout =00:30:00receiveTimeout =00:30:00的SendTimeout =00:30:00>
 

这就是我指的是,具体。

I have wcf service (S1) as client and another Wcf service(S2) as server. S1 consume S2 over net.tcp. S2 has one operation, which return a complex object with most of it's contents are string. The average size of this object is between 7-8 MB.

Recently I had to add more string contents to the actual object graph. This cause S2 to return following error

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'. 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)

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)

<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)

<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.

<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. Try setting them to something like 30 seconds and then working from there.

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.

这篇关于WCF服务 - 留言/对象大小相关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆