[英]Getting 400 error while uploading the image using the WCF services and Base64Request
I am trying to upload the image using the webservices and Base64string. 我正在尝试使用webservices和Base64string上传图像。
But each time I am trying to upload the image it gives me BAD REQUEST (400) Error. 但是每次我尝试上传图像时,它都会提示我错误请求(400)错误。
I have googled much about this, it says error is due to the large amount of data is been passed in request. 我对此进行了很多搜索,它说错误是由于在请求中传递了大量数据所致。
So I tried to increase the data length from web.config, but adding this. 因此,我尝试增加web.config中的数据长度,但添加了它。
<system.serviceModel>
<bindings>
<basicHttpBinding>
<!-- buffer: 64KB; max size: 64MB -->
<binding name="FileTransferServicesBinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00"
transferMode="Streamed" messageEncoding="Mtom" maxBufferSize="65536" maxReceivedMessageSize="67108864">
<security mode="None">
<transport clientCredentialType="None"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
</system.serviceModel>
But still it gives me the error. 但是仍然给我错误。
here is my function. 这是我的功能。
[OperationContract]
[WebInvoke(BodyStyle = WebMessageBodyStyle.Wrapped, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Xml)]
string AddAlbum(string imgstring)
And I am calling this function as follows :- 我称这个功能如下:-
public string PostRemoteJSON(string strurl, string param)
{
try
{
strurl = "http://mydomain.com/EventService.svc/AddAlbum";
param = "{\"imgstring\":\"BASE64STRINGCONTENT\"}";
WebRequest myWebRequest;
Stream myRequestStream;
StreamWriter myStreamWriter;
WebResponse myWebResponse;
myWebRequest = WebRequest.Create(strurl);
myWebRequest.Method = "POST";
myWebRequest.Timeout = 1000000;
myWebRequest.ContentType = "application/json";
myWebRequest.ContentLength = param.Length;
myRequestStream = myWebRequest.GetRequestStream();
myStreamWriter = new StreamWriter(myRequestStream);
myRequestStream = myWebRequest.GetRequestStream();
myStreamWriter.Write(param);
myStreamWriter.Flush();
myStreamWriter.Close();
myRequestStream.Close();
myWebResponse = myWebRequest.GetResponse();
StreamReader reader = new StreamReader(myWebResponse.GetResponseStream());
return reader.ReadToEnd();
}
catch (Exception ex)
{
return ex.Message;
}
}
Please help me. 请帮我。
Thanks 谢谢
Try setting maxBufferSize, maxArrayLength and maxReceiveMessageSize all to a value double (for testing) the size of your maximum request payload. 尝试将maxBufferSize,maxArrayLength和maxReceiveMessageSize全部设置为最大请求有效负载大小的两倍(用于测试)。 Setting it exactly to 64k does not account for serialization and protocol overhead and is too small.
将其精确设置为64k不能解决序列化和协议开销,并且它太小。
We were facing the same issue in our project . 我们在项目中面临着同样的问题。 I assume you were having this issue while debugging your app.
我认为您在调试应用程序时遇到了这个问题。 It seems like DevServer doesn't support streamed bindings.
似乎DevServer不支持流绑定。 If you have already tried to increase quotas and buffers, but it didn't solve the issue, try to deploy your app in IIS, for us it all works fine in IIS environment.
如果您已经尝试增加配额和缓冲区,但不能解决问题,请尝试在IIS中部署您的应用程序,因为对于我们来说,这一切在IIS环境中都可以正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.