2011-06-08 70 views
3

我想通過WCF使用WebHttpBinding傳遞base64編碼的字符串。WCF ProtocolException:錯誤的請求400(與http消息大小有關)

我得到了服務器沒有響應的神祕錯誤'Bad Request 400'。我知道它與字符串的大小有關,因爲如果我測試一個非常短的字符串(大約4KB左右),它可以工作,但任何更高的字符都不會。

我已經閱讀無處不在,這與綁定的web.config中的maxReceivedMessageSize或其他配置有關,但即使在更改客戶端和服務器上的這些數字後,我仍然得到錯誤(換句話說,我有閱讀其他職位的很多關於這個具體問題,但他們沒有似乎幫助)

伊夫證實,一切正常了下面的代碼的最後一行,其中引發錯誤:

static IHttpDataPush push = new HttpDataPush(); 

var wcfClient = ChannelHelperExtensions.WebHttpChannel<IHttpDataRcv>("http://localhost:3941/HttpRcv"); 

     var args = wcfClient.OptionArgs(); 

     foreach (var v in args) 
     { 
      HttpTransactionDataArgs uid = push.Option(v.Entity, v.Option, v.Key); 

      wcfClient.ResponseNotification(uid); <-- error thrown at this line 

這些是我的服務合同/數據合同:

[ServiceContract] 
public interface IHttpDataPush 
{ 
    [OperationContract] 
    HttpTransactionDataArgs DbRequest(HttpTransactionOptionArgs args); 

    [OperationContract] 
    [WebGet] 
    HttpTransactionDataArgs DbOption(string entity, string option, string key); 
} 

[DataContract] 
[KnownType(typeof(HttpTransactionDataArgs))] 
public class HttpTransactionDataArgs 
{ 
    [DataMember] 
    public string EntityName { get; set; } 

    [DataMember] 
    public string Base64Schema { get; set; } 

    [DataMember] 
    public string Base64Data { get; set; } 

    [DataMember] 
    public bool TransactionSuccessful { get; set; } 
} 

合同的數據推送的接收端:

[ServiceContract] 
public interface IHttpDataRcv 
{ 
    [OperationContract] 
    HttpTransactionOptionArgs[] OptionArgs(); 

    [OperationContract] 
    bool ResponseNotification(HttpTransactionDataArgs args); 
} 

[DataContract] 
[KnownType(typeof(HttpTransactionOptionArgs))] 
public class HttpTransactionOptionArgs 
{ 
    [DataMember] 
    public string Entity { get; set; } 

    [DataMember] 
    public string Option { get; set; } 

    [DataMember] 
    public string Key { get; set; } 
} 

服務器端的web.config:

<bindings> 
    <webHttpBinding> 
    <binding name="webHttpConfig" closeTimeout="00:20:00" openTimeout="00:20:00" 
     receiveTimeout="00:20:00" sendTimeout="00:20:00" 
     maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" > 
     <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" 
      maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> 
    </binding> 

<endpoint address="/HttpRcv" behaviorConfiguration="REST" bindingConfiguration="webHttpConfig" binding="webHttpBinding" contract="EmailContracts.IHttpDataRvc" /> 

客戶端web配置(其中引發錯誤:)

<client> 
    <endpoint address="http://localhost:3941/HttpRcv" 
      binding="webHttpBinding" 
      bindingConfiguration="webHttpConfig" 
      contract="EmailContracts.IHttpDataRcv" /> 
</client> 

    <bindings> 
    <webHttpBinding> 
    <binding name="webHttpConfig" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647"> 
     <readerQuotas maxStringContentLength="2147483647" maxArrayLength="2147483647" 
        maxDepth="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> 
    </binding>  
    </webHttpBinding> 
</bindings> 
+0

我不知道怎麼辦,但是如果您設置了Web服務的跟蹤,它可能會提供一些有用的信息,說明錯誤生成的原因。 – regex 2011-06-08 23:24:00

+0

我有跟蹤。沒有看到任何明顯的錯誤彈出,但我不太熱衷於如何瀏覽跟蹤日誌,但。我會進一步研究它。 – 2011-06-08 23:27:10

回答

1

您是否在IIS/ASP.NET中託管?如果是這樣,你還必須增加他們的設置。

對於IIS7,您要更改the system.webServer/security/requestFiltering/requestLimits/@maxAllowedContentLength

對於ASP.NET,您想要更改the system.web/httpRuntime/@maxRequestLength

+0

這是所有使用本地開發服務器的visual studio。 – 2011-06-09 08:45:47

+0

你嘗試設置它們嗎? httpRuntime也會影響Cassini開發服務器。這就是說,在某些時候你會將它部署到IIS的權利?所以你應該在那裏獲得system.webServer。 – 2011-06-09 14:24:46

+1

我確實增加了httpRuntime maxRequestLength,但仍然得到相同的錯誤。 – 2011-06-09 16:33:55