2009-08-05 57 views
3

我有一個WCF服務操作,它將一個對象作爲參數。這個對象有一個byte []屬性等等。客戶端程序使用svcutil生成的代理來調用此服務操作。WCF Web服務操作在傳遞超過50kb字節時拋出異常[]

當客戶端程序填充大小超過50Kb的對象的bype [] propery時,會拋出以下錯誤。 (雖然分配給字節[]的圖像尺寸小於50kb,但它工作正常)。

其中我正的錯誤是:

System.ServiceModel.ProtocolException了未處理 消息=「遠程服務器返回一個意外的響應:(400)錯誤的請求」

這是我的服務器端配置:

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

回答

3

好吧,我回答在這裏我自己的問題 -

剛剛發現在服務器端配置「maxReceivedMessageSize」中有一個設置。一旦你把它設置爲你希望服務器接受的最大尺寸,你就可以開始了。

感謝&問候, 阿賈伊

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>