3

我正在尝试使用 WebHttpBinding 通过 WCF 传递 base64 编码的字符串。

我收到服务器没有响应的神秘错误“错误请求 400”。我知道它与字符串的大小有关,因为如果我测试一个非常短的字符串(大约 4KB 左右)它可以工作,但任何稍高的字符串都不会。

我到处都读到这与 maxReceivedMessageSize 或 web.config 中用于绑定的其他配置有关,但即使在客户端和服务器上更改了这些数字后,我仍然会收到错误(换句话说,我已经阅读了很多其他关于这个确切问题的帖子,但他们似乎没有帮助?)

我已经确认一切正常,直到引发错误的以下代码的最后一行:

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

1 回答 1

1

您是否在 IIS/ASP.NET 中托管?如果是这样,您还必须增加它们的设置。

对于 IIS7 ,system.webServer/security/requestFiltering/requestLimits/@maxAllowedContentLength您要更改.

对于 ASP.NET ,system.web/httpRuntime/@maxRequestLength您想要更改.

于 2011-06-09T00:32:46.827 回答