none
How to send large image base 64 string to wcf service RRS feed

  • Question

  • I have a problem in calling of wcf rest service through ajax post method in javascript. I tried to sending large (kbs of data) string to wcf call and i am getting 400 bad request from server. when i trim string to light string it successfully call. ? please help me to find cause for this bad request from server

     

    my web config is as 

     

    <system.serviceModel>

        <bindings>

          <wsHttpBinding>

            <binding name="WSHttpBinding_IService" closeTimeout="00:01:00"

             openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"

             bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"

             maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text"

             textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">

              <readerQuotas

                            maxDepth="2147483647"

                            maxStringContentLength="2147483647"

                            maxArrayLength="2147483647"

                            maxBytesPerRead="2147483647"

                            maxNameTableCharCount="2147483647" />

              <reliableSession ordered="true" inactivityTimeout="00:10:00"

               enabled="false" />

            </binding>

          </wsHttpBinding>

     

        </bindings>

        <services>

    <service behaviorConfiguration="RestfulService.IRestServiceImplBehavior" name="RestfulService.RestServiceImpl">

            <endpoint address="" binding="webHttpBinding" contract="RestfulService.IRestServiceImpl" behaviorConfiguration="web">

    <identity>

    <dns value="localhost"/>

    </identity>

    </endpoint>

    </service>

    </services>

     

    <behaviors>

     

    <serviceBehaviors>

    <behavior name="RestfulService.IRestServiceImplBehavior">

    <serviceMetadata httpGetEnabled="true"/>

    <serviceDebug includeExceptionDetailInFaults="false"/>

    </behavior>

    </serviceBehaviors>

          <endpointBehaviors>

            <behavior name="web">

              <webHttp/>

            </behavior>

     

          </endpointBehaviors>

    </behaviors>

    </system.serviceModel>

     

    and ajax call is 

     

      function CallWcfAjax()

        {

     

            var url = "http://localhost:27034/RestServiceImpl.svc/";

           // url = url + "GetStudent";

            url = url + "SignUpUser";

     

            //string name, string email, string phoneNo, string gender, string country)

            var name = (document.getElementById("name").value).innerHTML;

            var email = (document.getElementById("email").value).innerHTML;

            var phone = (document.getElementById("phone").value).innerHTML;

            var gender = (document.getElementById("gender").value).innerHTML;

            var country = (document.getElementById("country").value).innerHTML;

            var body = '{"name":';

            body = body + name + ',"email":';

            body = body +email + ',"phoneno":';

            body = body + phone + ',"gender":';

            body = body + gender + ',"country":';

            body = body + country + '}';

            alert(body);

            // Send the HTTP request

            xmlHttp.open("POST", url, true);

            xmlHttp.setRequestHeader("Content-type", "application/json");

            xmlHttp.send(body);

     

            // Create result handler 

            xmlHttp.onreadystatechange = DisplayResult

        }

        function DisplayResult()

        {

     

            alert(xmlHttp.readyState);

            alert(xmlHttp.responseText);

     

             if(xmlHttp.readyState == 4)

             {

                  result.innerText = xmlHttp.responseText;

             }

        }

     

     

    Help me

     

     


    asthanarht
    Sunday, December 5, 2010 6:55 PM

Answers

  • Hello, please also configure WCF to allow sending large data:

        <bindings>
          <webHttpBinding>
            <binding maxReceivedMessageSize="10000000" receiveTimeout="01:00:00">
              <readerQuotas maxStringContentLength="10000000"/>
            </binding>
          </webHttpBinding>
        </bindings>

    In addition, you may want to check if the request body is correct. In most cases, if you want to send JSON data, please invoke JSON.stringify, which helps to construct a correct JSON object.


    Lante, shanaolanxing This posting is provided "AS IS" with no warranties, and confers no rights.
    • Marked as answer by asthanarht Tuesday, December 7, 2010 9:15 AM
    Tuesday, December 7, 2010 2:31 AM

All replies

  • increase the max request size in web.config:

     

    <system.web>

       <httpRuntime 

             executionTimeout="90"

             maxRequestLength="50000"/>

     </system.web>

     

    if this does not help turn on wcf trace log on the server.


    http://webservices20.blogspot.com/
    WCF Security, Interoperability And Performance Blog
    Sunday, December 5, 2010 9:21 PM
  • Still getting same 400 server error  :(  Any more settings
    asthanarht
    Monday, December 6, 2010 5:13 PM
  • turn on wcf trace log to see detailed errors
    http://webservices20.blogspot.com/
    WCF Security, Interoperability And Performance Blog
    Monday, December 6, 2010 8:32 PM
  • Hello, please also configure WCF to allow sending large data:

        <bindings>
          <webHttpBinding>
            <binding maxReceivedMessageSize="10000000" receiveTimeout="01:00:00">
              <readerQuotas maxStringContentLength="10000000"/>
            </binding>
          </webHttpBinding>
        </bindings>

    In addition, you may want to check if the request body is correct. In most cases, if you want to send JSON data, please invoke JSON.stringify, which helps to construct a correct JSON object.


    Lante, shanaolanxing This posting is provided "AS IS" with no warranties, and confers no rights.
    • Marked as answer by asthanarht Tuesday, December 7, 2010 9:15 AM
    Tuesday, December 7, 2010 2:31 AM
  • Hi asthanarht,

    I am also getting the same 400 server error.

    Please help me out if you have any solution.

    Tuesday, June 12, 2012 8:40 AM