How to assemble a .net web request in javascript
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.
function getSoapEnvelope(wsFunction, wsNamespace, paramHash){
var envelope = '';
envelope += '<?xml version="1.0" encoding="utf-8"?>' + "\n"
envelope += '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' + "\n"
envelope += ' <soap:Body>' + "\n"
envelope += ' <' + wsFunction + ' xmlns="' + wsNamespace + '">' + "\n"
if (paramHash.length > 0){
var keys = paramHash.keys();
var values = paramHash.values();
for (var i = 0; i < paramHash.length; i++){
envelope += " <" + keys[i] + ">";
envelope += values[i];
envelope += "</" + keys[i] + ">\n";
}
}
envelope += ' </' + wsFunction + '>' + "\n"
envelope += ' </soap:Body>' + "\n"
envelope += '</soap:Envelope>'
return envelope
}
3 comments so far
Leave a reply
These are two nice examples of how to use mootools and .net web services, however, I guess I’m a little dumb. I wasn’t able to use these two functions combined.
How do I set this soapEnvelope to the mootools ajax request?
do I replace:
.request(‘SoapEnvelope’);
by
.request(getSoapEnvelope(‘function’, ‘namespace’, myHash);
Could you please post another example with the full code? thanks
Actually. It works really fine. I was missing a quote character when passing the envelope to the request
yea, I don’t like this word press formatting too much. It is hard to paste code and make it look right (and be able to copy it). I’m looking into some alternatives right now, and I’ll probably start posting text files with the code for download.