传递超过50kb byte []时,WCF Web服务操作会抛出异常

时间:2009-08-05 12:21:44

标签: .net wcf web-services

我有一个WCF服务操作,它将一个对象作为参数。该对象具有byte []属性等。客户端程序使用svcutil生成的代理调用此服务操作。

当客户端程序填充对象的bype [] propery,其大小超过50Kb时,会抛出以下错误。 (当分配给byte []的图像大小小于50kb时,它可以工作)。

我得到的错误是:

  

System.ServiceModel.ProtocolException未处理    Message =“远程服务器返回了意外响应:(400)Bad Request。”

这是我的服务器端配置:

<system.serviceModel>
<diagnostics>
   <messageLogging logMalformedMessages="false" logMessagesAtServiceLevel="false"
    logMessagesAtTransportLevel="false" />
</diagnostics>
<services>
  <service behaviorConfiguration="ProjectABC.ABCServiceBehavior"
    name="ProjecXAPI.ContentService">
        <endpoint address="" binding="basicHttpBinding" bindingConfiguration="testContentBinding"
         bindingName="testContentBinding" contract="ProjectABC.IABCtService" />
        <endpoint address="mex" binding="mexHttpBinding" bindingConfiguration="higherMessageSize_MEX"
         contract="IMetadataExchange" />
  </service>
</services>
<behaviors>
    <serviceBehaviors>
        <behavior name="ProjectABC.ABCServiceBehavior">
            <serviceMetadata httpGetEnabled="true"/>
                  <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
            <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
    </serviceBehaviors>
</behaviors>
<bindings>
  <basicHttpBinding>
    <binding name="testContentBinding" messageEncoding="Mtom" transferMode="Buffered">
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647"
                    maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
      <security mode="None"></security>
    </binding>
  </basicHttpBinding>
  <mexHttpBinding>
    <binding name="higherMessageSize_MEX"/>
  </mexHttpBinding>
</bindings>
</system.serviceModel>

这是我的客户端配置:

<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="testContentBinding_IContentService" closeTimeout="01:01:00"
        openTimeout="01:01:00" receiveTimeout="01:10:00" sendTimeout="01:01:00"
        allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
        maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
        messageEncoding="Mtom" textEncoding="utf-8" transferMode="Buffered"
        useDefaultWebProxy="true">
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647"
          maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
      <security mode="None">
        <transport clientCredentialType="None" proxyCredentialType="None"
            realm="" />
        <message clientCredentialType="UserName" algorithmSuite="Default" />
      </security>
    </binding>
  </basicHttpBinding>
</bindings>

<client>
  <endpoint address="http://localhost:2361/Content/ContentService.svc"
            binding="basicHttpBinding" bindingConfiguration="testContentBinding_IContentService"
            contract="IContentService" name="testContentBinding_IContentService" />
</client>
</system.serviceModel>

2 个答案:

答案 0 :(得分:3)

好的,我在这里回答我自己的问题 -

刚刚发现服务器端配置“maxReceivedMessageSize”中有一个设置。一旦将此值设置为您希望服务器接受的最大大小,您就可以开始使用了。

谢谢&amp;问候, 阿贾伊

答案 1 :(得分:0)

这是问题的解决方案。服务器端配置需要进行一些设置,如下所示:

<basicHttpBinding>
<binding name="ExampleBinding" transferMode="Buffered" messageEncoding="Mtom" maxReceivedMessageSize="104857600" maxBufferPoolSize="524288">
  <readerQuotas maxDepth="32" maxStringContentLength="104857600" maxArrayLength="104857600"
      maxBytesPerRead="4096" maxNameTableCharCount="104857600" />
  <security mode="None">
    <transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
    <message clientCredentialType="UserName" algorithmSuite="Default"/>
  </security>
</binding>
</basicHttpBinding>