开发者

WCF ProtocolException : Bad Request 400 (related to http message size)

I am trying to pass a base64 encoded string over WCF using WebHttpBinding.

I get the cryptic error 'Bad Request 400' that the server is not responding. I know its related to the size of the string because if I test a very short string (around 4KB or so) it works, but anything even slightly higher does not.

I've read everywhere that this is related to the maxReceivedMessageSize or other configuration in web.config for the binding, but even after changing those figures on both the client AND server I still get the error (in other words I have read alot of other posts about this exact problem but they didnt seem to help?)

Ive confirmed that everything is working properly up to the last line of the following code where the error is thrown:

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

These are my service contracts / data contracts:

[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; }
}

Contracts for the receiving end of the data push:

[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; }
}

Server-side web.config:

<bindings>
  <webHttpBinding>
    <binding name="webHttpConfig" closeTimeout="00:20:00" openTimeout="00:20:00"
        receiveTimeout="00:20:00" sendTimeout="00:20:00"
        maxBufferS开发者_开发技巧ize="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" />

Client-side web config (where the error is thrown:)

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


Are you hosting in IIS/ASP.NET? If so you must also increase their settings as well.

For IIS7 you want to change the system.webServer/security/requestFiltering/requestLimits/@maxAllowedContentLength.

For ASP.NET you want to change the system.web/httpRuntime/@maxRequestLength.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜