首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WebServiceHost大型输入\输出字符串

WebServiceHost大型输入\输出字符串
EN

Stack Overflow用户
提问于 2013-06-10 19:12:55
回答 1查看 465关注 0票数 1

服务器代码:

代码语言:javascript
复制
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
    }
}

客户端代码:

代码语言:javascript
复制
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,我仍然得到“400Bad Request”。完全相同的代码,只是输入的字符串很少,所以...我如何让这段代码能处理更大的输入字符串呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-06-10 20:25:03

您的代码中存在错误。您正在使用WebServiceHost (WCF REST编程模型)和basicHttpbinding (WCF SOAP编程模型)。您不能将这两种方法混为一谈。

使用ServiceHost a WebHttpBinding解决此问题。

此外,请注意,对于WCF REST样式绑定,您需要确保IIS可以支持更大的传输-默认情况下是4096 (4MB)

检查你的web.config --你有这样的条目吗?

代码语言:javascript
复制
<system.web>
     ......
     <httpRuntime maxRequestLength="32678"/>  
     ......
</system.web>

即使我设置了binding对象的MaxReceivedMessageSize,我仍然得到“400Bad Request”

这只是一个“糟糕的请求”。检查WCF服务器日志以获取确切的错误消息。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17022573

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档