How to call a .net web service using mootools

Recently I have been trying the mootools library. One of the first task I wanted to be able to do, was to call a .net web service. The mootools ajax object defaults to urlEncoded = true. When method = post, and enlEncoded = true, then the content type is hard coded to application/x-www-form-urlencoded. To call the web service all you have to so it set urlEncoded = false, method = post, add the text/xml header, and add the SOAPAction header.


new Ajax('url here', {
method: 'post',
urlEncoded: false,
headers: {'Content-Type': 'text/xml; charset="utf-8"', 'SOAPAction': 'namespace/functionname'},
onComplete: function(webServiceResponse) {
// do something with webServiceResponse
},
onFailure: function() {
alert("ajax failure");
}
}).request('SoapEnvelope');

6 comments so far

  1. Kevin on

    I was hoping could post a little more info about this. Are you consuming a web service on the same domain or from a remote server?

    Also, what is the “SoapEnvelope” in .request(‘SoapEnvelope’)?

    This could be cool if it ends up working.

  2. robinbonin on

    We are only using this to call web services on our own domain. Accessing a webservice on another domain will have some security restrictions, and I wouldn’t trust it to work.

    I will post my function to create the soap envelope in a new post later today.

  3. [...] Posted in Uncategorized This is the function that I used to generate a web service request (soap envelope) using mootools. The mootools hash is the only moo tools specific feature used in this example and is should easily be ported over to any other library, or just regular javascript using overloaded parameters. I use this function in conjunction with my other post on calling a .Net Web Service via mootools. [...]

  4. Martin on

    Hi there,

    Would it be possible to call a .aspx WebMethod with this or is it only possible to call a webservice ?

  5. robinbonin on

    Honestly I didn’t realize that you could have web methods inside an aspx page. Looking at this article, it seems like it would work. http://asp.net/ajax/documentation/live/tutorials/ExposingWebServicesToAJAXTutorial.aspx

  6. Martin on

    Yep I have read that one, but is it possible to do the same thing using MooTools ?


Leave a reply