您好我有以下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更改为类型字符串,但无济于事,有人可以向我解释这是如何完成的吗?
配置设置
<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>
答案 0 :(得分:0)
您需要在客户端和服务器中设置一些参数。因为您需要能够上传(客户端),发送(客户端)和接收(服务器)大文件。
在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>
避免大邮件攻击: