user1390378
user1390378

Reputation: 433

How to send large data to web service?

I have a web service and I am sending a large string (approx. size is 700000 characters) as a argument. I am calling this web service from javascript (ScriptManager).

Problem is that when string length is around 100000 it hit web service successfully, but if string length is around 700000 it fails to hit web service and it gives this massage Error Message

JS Code

MyService.SendData("large string data", function (str) { }, function (err1) { alert(err1.get_exceptionType); });

WebService Code

[WebMethod(Description = "Test", EnableSession = true)]    
public void SendData(string str)
{//Here is breakpoint.
   //My code
}

So my question is how to send large string data to web service?

Upvotes: 1

Views: 2314

Answers (2)

Learner
Learner

Reputation: 4004

Few suggestions:

Increase the “maxQueryStringLength” property in the web.config file as below:

<system.web>
   <httpRuntime maxQueryStringLength="2097151"/>
</system.web>

Also, if the service is being hosted by IIS, you might want to add the below code in the web.config so that the server does not refuse to accept bigger size XML sent by us:

<system.webServer>
   <security>
     <requestFiltering>
       <requestLimits maxQueryString="2097151"/>
     </requestFiltering>
   </security>
</system.webServer>

But, I would suggest you to try consuming web service methods using jQuery instead of plain JS as I think there is something you are not doing right if you are passing the whole message in a URL. Technically, your service must be either GET or POST call.

A few great tutorials on consuming ASMX web methods using jQuery: http://encosia.com/using-jquery-to-consume-aspnet-json-web-services/

http://www.mikesdotnetting.com/Article/97/Cascading-DropDownLists-with-jQuery-and-ASP.NET

Upvotes: 0

Brad M
Brad M

Reputation: 7898

Use a POST request instead of GET. Data is then appended to the request's body instead of the query string. (You would have to configure your web service to accept POST requests)

GET is limited by the max length of the query string, and in the case of some versions of IE, this may be 2000 characters.

Upvotes: 5

Related Questions