简体   繁体   English

使用WCF服务和Base64Request上传图像时出现400错误

[英]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.

相关问题 使用 GET 访问 WCF 休息服务时出现 400 http 错误请求错误 - Getting 400 http bad request error while accessing WCF rest service using GET 上载图片asp.net MVC时出现Base64错误 - Getting Base64 error when uploading an image asp.net MVC 以base64格式上传图片时不允许使用关键字符 - Disallowed key characters while uploading image in base64 format 收到错误代码400剩余WCF客户端错误请求 - Getting Error Code 400 Bad Request for Rest WCF Client WCF:为什么我总是收到400 Bad Request Error? - WCF: Why do I keep getting a 400 Bad Request Error? 尝试使用wcf上传50kb大小的图像时,显示错误“远程服务器返回了意外的响应:(400)错误的请求。” - While trying to upload image of 50kb size using wcf , shows error 'The remote server returned an unexpected response: (400) Bad Request.' 与WCF服务一起使用的Base64编码图像 - Base64 Encoding Image using with WCF Service 上传 Base64 字符串中超过 7MB 的图像时如何防止出现 500(内部服务器错误) - How to prevent from 500 (Internal Server Error) while uploading the more than 7MB image in Base64 string WCF数据服务:SaveChanges:处理此请求时发生错误 - WCF Data Services: SaveChanges: An error occurred while processing this request 图形 API - 获取“远程服务器返回错误:(400)错误请求。”使用多租户请求 AccessToken 时出错 - Graph API - Getting "The remote server returned an error: (400) Bad Request."Error while request AccessToken using multiTenant
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM