开发者

Getting 400 error while uploading the image using the WCF services and Base64Request

开发者 https://www.devze.com 2023-03-26 16:27 出处:网络
I am trying to upload the image using the webservices and Base64string. But each time I am trying to upload the image it gives me BAD REQUEST (400) Error.

I am trying to upload the image using the webservices and Base64string.

But each time I am trying to upload the image it gives me BAD REQUEST (400) Error.

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.

 <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;
        }
    }

Pl开发者_如何学JAVAease help me.

Thanks


Try setting maxBufferSize, maxArrayLength and maxReceiveMessageSize all to a value double (for testing) the size of your maximum request payload. Setting it exactly to 64k does not account for serialization and protocol overhead and is too small.


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. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号