how to pass soap header
Hi , i am calling a web service using Ti suds client
now to authenticate for web service it needs a soap header with parameters
how to pass soap header in this
pls help .
Somesh
2 Answers
-
I think in the suds.js file that is including in the Kitchen Sink app, there is a section below that would need to be modified. I am having the same issue and MUST solve this.
If you look at the "envelopeBegin:" it only gives the "" tag. I need a SOAP header tag like below to call my DNN site. I will be messing with this and if I get a fix, I will post it. Or Appcelerator can. :)
<IWebAuthendicationHeader > <PortalID>int</PortalID> <UserID>int</UserID> <Username>string</Username> <Password>string</Password> <Encrypted>string</Encrypted> <WebPageCall>string</WebPageCall> <ModuleId>int</ModuleId> </IWebAuthendicationHeader>
in suds.js:
// Client Configuration
var config = extend({
endpoint:'http://localhost',
targetNamespace: 'http://localhost',
envelopeBegin: '<?xml version="1.0" encoding="utf-8"?>',
envelopeEnd: ''
},_options);
Dale Bingham
-
Here is what I tried to do in a 'sudsheader.js' file that was copied from suds.js. Wherever you would have included suds.js include the new file and do not mess up the original one that works. :) It is actually returning what I need it to after 5 hrs of pain… you know the drill.
There may be cleaner ways to do this, as this is more of a hack to get it running, however it injects the soap:Header right where it needs to be w/o replacing any underlying .js files. Comment out the Titanium.API.info if you don't want to see it in the console. I wanted to know exactly what XML was being passed.
Note for my WS I also did not need the ns0: in front of my calls or XML tags so I did a '' for blanks. Use whatever your WS needs
// inside the envelopeBegin after the /envelope/" and before the soap body add a // variable you will replace xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">SOAPHEADERPLACEHOLDER<soap:Body>
Create the SOAP HEADER STRING. If nothing is passed in it should skip it and call the function normally
// Dale Bingham: 08/03/2011 create soapBody string for xhr.send // Allow straight string input for XML body - if not, build from object if (typeof soapBody !== 'string') { soapBody= '<soap:Header><'+_soapActionHeader+' xmlns="' + config.targetNamespace + '">'; soapBody += convertToXml(_soapBody, ''); soapBody += '</'+_soapActionHeader+'></soap:Header>'; }
Replace the SOAP Header string variable with the body you just made and call xhr.send normally
var ebegin = config.envelopeBegin; config.envelopeBegin = ebegin.replace('PLACEHOLDER', config.targetNamespace); var ebeginSoap = config.envelopeBegin; config.envelopeBegin = ebeginSoap.replace('SOAPHEADERPLACEHOLDER', soapBody); // show what I am concatenating and replacing Titanium.API.info(config.envelopeBegin);
You also now have to call the .invoke with 2 extra parameters in whatever .js file is running your application: the name that goes inside the soap:Header and then the header parameters
var headerparams = { Username: 'xxxxxxxxxxx', Password: 'xxxxxxxxxx', }; suds.invoke('NAME_OF_HEADER_ITEM', headerparams, 'NAME_OF_WEBSERVICE_CALL', callparams, function(xmlDoc) {
I am actually using this to call an XML web service within DotNetNuke using IWeb however this can be modified for any authentication information passed in the header to make a more secure webservice call. http://www.codeproject.com/KB/cpp/authforwebservices.aspx has more information on authentication for web services