[英]Increase WCF service upload size
您好,我有以下WCF服務,需要一個byte []和一個ID
public string SaveImagesToServer(byte[] images, Int64 id)
{
try
{
var ms = new MemoryStream(images);
var fs = new FileStream(System.Web.Hosting.HostingEnvironment.MapPath("~/Images/") + id + "-" + "Testing", FileMode.Create);
ms.WriteTo(fs);
ms.Close();
fs.Close();
fs.Dispose();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
return ex.ToString();
}
return "Success";
}
如您所見,它返回一個字符串(我希望如此),但是相反,它返回text / html,如此處所示,此錯誤是我在調用它時得到的
響應消息的內容類型text / html與綁定的內容類型不匹配(text / xml; charset = utf-8)。 如果使用自定義編碼器,請確保正確實施IsContentTypeSupported方法。 響應的前1024個字節為:'
我搜索了互聯網,試圖弄清楚如何將其返回類型從text / html更改為string類型,但無濟於事,有人可以向我解釋一下如何完成此操作嗎?
配置設置
<bindings>
<basicHttpBinding>
<binding name="uploadfilebinding" closeTimeout="10:01:00"
maxBufferSize="204857600" maxBufferPoolSize="204857600"
maxReceivedMessageSize="104857600" openTimeout="10:01:00"
receiveTimeout="10:10:00" sendTimeout="10:01:00"
messageEncoding="Mtom" transferMode="StreamedRequest">
<readerQuotas maxDepth="204857600" maxStringContentLength="204857600"
maxArrayLength="204857600" maxBytesPerRead="204857600"
maxNameTableCharCount="204857600" />
</binding>
</basicHttpBinding>
</bindings>
您需要在客戶端和服務器中都設置一些參數。 因為您需要能夠上傳(客戶端),發送(客戶端)和接收(服務器)大文件。
在WCF服務的Web.config中,我添加了以下參數以避免此類問題:
<system.web>
<httpRuntime ... maxRequestLength="2147483647" />
</system.web>
...
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding ... maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="2147483647">
<readerQuotas maxArrayLength="2147483647" maxStringContentLength="2147483647" />
...
</binding>
</basicHttpBinding>
</bindings>
在客戶端的Web.config中,添加以下參數:
<system.web>
...
<httpRuntime ... maxRequestLength="40960" />
</system.web>
...
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding maxReceivedMessageSize="41943040" maxBufferSize="41943040" maxBufferPoolSize="41943040">
<readerQuotas maxArrayLength="41943040" maxStringContentLength="41943040" />
</binding>
</basicHttpBinding>
</bindings>
...
</system.serviceModel>
為避免攻擊大型郵件:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.