繁体   English   中英

具有大参数的WCF服务

[英]WCF Service with large parameters

我已经看过许多关于SO的类似主题,但是还没有找到一个有助于解决这个问题的主题。

有一个采用XML处理的WCF服务。 我正在读取的XML文件约为600K。

该调用适用于小型xml文件(大多数情况下),但是在较大的文件上,我收到错误消息:

System.ServiceModel.Security.MessageSecurityException:
接收到来自另一方的不安全或不正确安全的故障。 有关错误代码和详细信息,请参见内部FaultException。

内部异常是:

System.ServiceModel.FaultException:
无法处理该消息。 这很可能是因为操作'http://tempuri.org/ISapListener/ProcessSapRoles'不正确,或者是消息包含无效或过期的安全上下文令牌,或者是绑定之间不匹配。 如果服务由于不活动而中止通道,则安全上下文令牌将无效。 为防止服务中止空闲会话,请过早增加服务端点绑定上的接收超时。

就像我说的...它适用于小型文件,并且我的打开,发送,接收,关闭和不活动超时都设置为10分钟。 它在大约20-30秒内失效。

另外,服务器和客户端上的时钟完全同步(我已经看到了它作为答案)。

我当前的配置文件(我已经进行了很多设置):

服务器:

<bindings>
  <wsHttpBinding>
    <binding name="wsHttpBinding_Custom" closeTimeout="00:00:10"
             openTimeout="00:01:00" receiveTimeout="00:10:00"
             sendTimeout="00:10:00" bypassProxyOnLocal="false" 
             transactionFlow="false" hostNameComparisonMode="StrongWildcard"
             messageEncoding="Text" textEncoding="utf-8" 
             useDefaultWebProxy="true" allowCookies="false"
             maxReceivedMessageSize="1024768"            
             maxBufferPoolSize="1024768" >
      <readerQuotas maxDepth="32" maxBytesPerRead="4096" 
                    maxNameTableCharCount="16384" />
      <reliableSession ordered="true" inactivityTimeout="00:10:00" 
                       enabled="false" />
      <security mode="Message">
        <transport clientCredentialType="Windows" proxyCredentialType="None" 
                   realm="" />
        <message clientCredentialType="Windows" 
                 negotiateServiceCredential="true"
                 algorithmSuite="Default" />
      </security>
    </binding>
  </wsHttpBinding>
</bindings>
<services>
  <service behaviorConfiguration="CSA.GS3.Services.SapListenerBehavior" 
           name="CSA.GS3.Services.SapListener">
    <endpoint address="" binding="wsHttpBinding"  
              bindingConfiguration="wsHttpBinding_Custom" 
              contract="CSA.GS3.Services.ISapListener">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" 
              contract="IMetadataExchange" />
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="CSA.GS3.Services.SapListenerBehavior">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>

客户:

<bindings>
  <wsHttpBinding>
    <binding name="WSHttpBinding_ISapListener1" 
             closeTimeout="00:10:00" openTimeout="00:10:00" 
             receiveTimeout="00:10:00" sendTimeout="00:10:00"
             bypassProxyOnLocal="false" transactionFlow="false"
             hostNameComparisonMode="StrongWildcard"
             messageEncoding="Text" textEncoding="utf-8" 
             useDefaultWebProxy="true" allowCookies="false"
             maxBufferPoolSize="1024768" 
             maxReceivedMessageSize="1024768">
      <readerQuotas maxDepth="32" maxBytesPerRead="4096" 
                    maxNameTableCharCount="16384" />
      <reliableSession ordered="true" inactivityTimeout="00:10:00"
                       enabled="false" />
      <security mode="Message">
        <transport clientCredentialType="Windows" proxyCredentialType="None"
          realm="" />
        <message clientCredentialType="Windows" 
                 negotiateServiceCredential="true"
                 algorithmSuite="Default" />
      </security>
    </binding>
  </wsHttpBinding>
</bindings>
<client>
  <endpoint address="http://gs3-test.us.tycoelectronics.com/SapListener/SapListener.svc"
            binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_ISapListener1"
            contract="Gs3TestSapListener.ISapListener" 
            name="WSHttpBinding_ISapListener1">
    <identity>
      <dns value="localhost" />
    </identity>
  </endpoint>
</client>

我确实在该服务上启用了跟踪,但是从日志文件中看不出来。

在使用配置设置时收到的其他异常:

System.ServiceModel.Security.SecurityNegotiationException
无法打开安全通道,因为与远程端点的安全协商失败。

System.ServiceModel.ServiceActivationException
请求的服务“ http://../SapListener.svc”无法激活。

如果您认为能够从日志文件中解脱出来对您有所帮助,请使用svcTraceViewer。 只要确保您已正确设置跟踪即可。 我的博客上有一篇关于此的文章。 svcTraveViewer调试WCF服务

关于大型有效负载,您可能需要看一下这篇MSDN文章。 http://msdn.microsoft.com/en-us/library/ms733742.aspx

特别是流数据。

System.ServiceModel.ServiceActivationException
The requested service, 'http://../SapListener.svc' could not be activated.

这可能是编译错误或无效的配置。

是WCF 4.0吗? 然后,您可以删除自定义配置并使用自动绑定。 我还建议您尝试使用除wsHttpBinding之外的其他绑定,例如basicHttpBinding。

我能够使它与以下配置一起使用:

服务器:

<bindings>
  <wsHttpBinding>
    <binding name="wsHttpBinding_Custom"
             closeTimeout="00:10:00"
             openTimeout="00:10:00"
             receiveTimeout="00:10:00"
             sendTimeout="00:10:00"
             maxReceivedMessageSize="2097152"
             bypassProxyOnLocal="false" transactionFlow="false" 
             hostNameComparisonMode="StrongWildcard"
             maxBufferPoolSize="2097152" messageEncoding="Text"
             textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
      <readerQuotas maxDepth="32" maxBytesPerRead="4096" 
                    maxNameTableCharCount="16384" />
      <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" />
      <security mode="Message">
        <transport clientCredentialType="Windows" proxyCredentialType="None" 
                   realm="" />
        <message clientCredentialType="Windows" negotiateServiceCredential="true" 
                 algorithmSuite="Default" />
      </security>
    </binding>
  </wsHttpBinding>
</bindings>

客户:

<bindings>
  <wsHttpBinding>
    <binding name="WSHttpBinding_ISapListener1" closeTimeout="00:10:00"
             openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
             bypassProxyOnLocal="false" transactionFlow="false" 
             hostNameComparisonMode="StrongWildcard"
             maxBufferPoolSize="2097152" 
             maxReceivedMessageSize="2097152"
             messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
             allowCookies="false">
      <readerQuotas maxDepth="32" maxBytesPerRead="4096" 
                    maxNameTableCharCount="16384" />
      <reliableSession ordered="true" inactivityTimeout="00:10:00"
                       enabled="false" />
      <security mode="Message">
        <transport clientCredentialType="Windows" proxyCredentialType="None"
                   realm="" />
        <message clientCredentialType="Windows" negotiateServiceCredential="true"
                 algorithmSuite="Default" />
      </security>
    </binding>
  </wsHttpBinding>
</bindings>

我能看到的唯一区别是我碰到了maxReceivedMessageSize和maxBufferPoolSize ...也许我错过了其他东西吗? 如果那是问题,那么问题是我的通话开销为我发送的600K xml数据增加了额外的400 + K

如果可能并为客户端所接受,您可以将文件分解为较小的块,然后进行发送,前提是您没有客户端的数字证书等和排序选项。

暂无
暂无

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

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