1

サーバーコード:

WebServiceHost w = new WebServiceHost(typeof(WebHost), new Uri("http://localhost/Host");
BasicHttpBinding binding = new BasicHttpBinding();
binding.MaxBufferPoolSize = 2147483647;
binding.MaxBufferSize = 2147483647;
binding.MaxReceivedMessageSize = 2147483647;
binding.ReaderQuotas = new XmlDictionaryReaderQuotas { MaxStringContentLength = 2147483647 };
w.AddServiceEndpoint(typeof(WebHost), binding, "http://localhost/Host");
w.Open();


[ServiceContract]
public class HEWebHost
{
    [OperationContract]
    [WebInvoke(UriTemplate = "Host")]
    public string Host(string largeRequest)
    {
    // ... Some code
    }
}

クライアントコード:

HttpWebRequest request = HttpWebRequest.Create("http://localhost/Host") as HttpWebRequest;
request.Method = "POST";
StreamWriter writer = new StreamWriter(request.GetRequestStream());
writer.Write(largeRequestString);
writer.Flush();
writer.Close();
writer.Dispose();

HttpWebResponse response = request.GetResponse() as HttpWebResponse;
StreamReader reader = new StreamReader(response.GetResponseStream());
string output = reader.ReadToEnd();

バインディング オブジェクトの MaxReceivedMessageSize を設定しても、「400 Bad Request」が表示されます。まったく同じコードで、小さな文字列入力のみで完全にうまく機能するので...このコードをより大きな入力文字列で機能させるにはどうすればよいですか?

4

1 に答える 1

1

コードに何か問題があります。WebServiceHost(WCF REST プログラミング モデル) と basicHttpbinding (WCF SOAP プログラミング モデル)を使用しています。2 つのアプローチを混在させることはできません。

ServiceHostまたはWebHttpBinding を使用して問題を修正してください。

また、WCF REST スタイル バインディングの場合、IIS がより大きな転送をサポートできることを確認する必要があることに注意してください。デフォルトでは 4096 (4 MB) です。

web.config を確認してください - このようなエントリはありますか?

<system.web>
     ......
     <httpRuntime maxRequestLength="32678"/>  
     ......
</system.web>

バインディング オブジェクトの MaxReceivedMessageSize を設定しても、「400 Bad Request」が表示されます

それはただの「悪い要求」です。WCF サーバー ログを確認して、正確なエラー メッセージを取得します。

于 2013-06-10T12:25:02.807 に答える