我收到错误
尝试发出请求时发生Web异常。远程服务器返回错误:(413)请求实体太大。:
尝试从ASP.Net Web应用程序上传文件到Sharepoint站点时。用户添加通过ASP.Net文件上载控件选择文件,下面的代码将其上传到Sharepoint。我试图上传的文件大约是250k(即不是很大)。
代码如下:
public string SharepointWebClientSOAPPost(Uri webService, string SOAPAction, string contentType, string postData, NetworkCredential networkCredential = null, string webProxy = "", NetworkCredential webserviceCredentials = null)
{
try
{
using (WebClient client = new WebClient())
{
if (string.IsNullOrEmpty(webProxy) && webserviceCredentials != null)
{
client.Proxy = new WebProxy(new Uri(webProxy));
client.Proxy.Credentials = webserviceCredentials;
}
if (networkCredential != null)
{
client.Credentials = networkCredential;
}
client.Headers.Add(HttpRequestHeader.ContentType, contentType);
client.Headers.Add("SOAPAction", SOAPAction);
// Apply ASCII Encoding to obtain the string as a byte array.
var byteArray = Encoding.ASCII.GetBytes(postData);
// Upload the input string using the HTTP 1.0 POST method.
var responseArray = client.UploadData(webService, "POST", byteArray);
// Decode and return the response.
var response = Encoding.ASCII.GetString(responseArray);
return response;
}
}
catch(Exception ex)
{
//etc.
}
}
我在web.config中有以下设置
<httpRuntime maxRequestLength="1024000" />
如果我使用几k的文本文件,它工作正常,所以我认为基本的想法是正确的(SOAP消息格式正确,URL正确)。但是,运行SP站点的人告诉我,它被配置为接受最大50MB的文档。
我可以开始寻找问题的任何想法吗?
答案 0 :(得分:1)
您的代码使用WCF上传文件而不是ASP.NET,您必须像这样配置web.config maxReceivedMessageSize :
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding maxReceivedMessageSize="10485760">
</binding>
</basicHttpBinding>
</bindings>
</system.serviceModel>