views:

356

answers:

2

Hi.

I am am trying to connect to a SOAP web service using ksoap2 library. I have read a bunch of docs about it, but i am stuck as my request is not an ordinary one.

I need to specify some headers prior to sending the request.

when is use a soap client to test the webservice i also need to put this in the soap enveope header section:

<SOAP-ENV:Header>
<mns:AuthIn xmlns:mns="http://enablon/wsdl/"
 SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"&gt;
 <UserInfo xsi:type="wsdlns:AuthHeader">
  <EnaHomeSite xsi:type="xsd:string">sss</EnaHomeSite>
  <EnaUserName xsi:type="xsd:string">sadsa</EnaUserName>
  <EnaPassword xsi:type="xsd:string">qwertf</EnaPassword>
 </UserInfo>
</mns:AuthIn>
</SOAP-ENV:Header>

The rest of my code is similar to this approach

The emulator takes a bit of time to precess so i assume it contacts the server, but the call to ...call crases with:

org.xmlpull.v1.XmlPullParserException: expected: END_TAG {http://schemas.xmlsoap.org/soap/envelope/}Body (position:END_TAG </{http://schemas.xmlsoap.org/soap/envelope/}SOAP-ENV:Fault&gt;@1:505 in java.io.InputStreamReader@43ef45e8) 

My question is how do i attach the header mentioned above to my request?

I didn't manage to fine nice doc for ksoap. maybe some tutorials or examples. can anyone point me to some docs. I have found the javadoc, but it is rather thin.

I have also tried to format my own raw HTTP request. (managed to do so on iPhone and it works just fine). However i can't seem to be able to add the body of the request in. I mean the big soap xml containing all headers namespaces and required data for the call. Any pointer on this direction would be also much appreciated.

Thanks a lot, guys.

Cheers, Alex

+1  A: 

I have encountered same issue and for that i have created Header in following way,


public static Element[] addheader()
    {
           Element[] header = new Element[1];
           header[0] = new Element().createElement("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd","Security");
           header[0].setAttribute(null, "mustUnderstand","1");
           Element usernametoken = new Element().createElement("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "UsernameToken");
          // usernametoken.addChild(Node.TEXT,"");
           usernametoken.setAttribute("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd", "Id", "UsernameToken-4");
           header[0].addChild(Node.ELEMENT,usernametoken);
           Element username = new Element().createElement(null, "n0:Username");
           username.addChild(Node.TEXT, "username_value");
           //username.setPrefix("n0", null);
           usernametoken.addChild(Node.ELEMENT, username);
           Element pass = new Element().createElement(null, "n0:Password");
           //pass.setPrefix("n0",null);
           pass.setAttribute(null, "Type", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText");
           pass.addChild(Node.TEXT, "password_value");

           usernametoken.addChild(Node.ELEMENT, pass);
           return header;
    }

and add this header as soapEnvelope.headerOut = addheader();

As it is working for me, if should work for you.

Rajnikant
A: 

Hi Rajnikant,

Is the Header elements URL is same for all is need to be changed based on web service called. i have tried with the solution which you have provided but no luck. moreover i didn't understand your solution properly.. i would appreciate if you elaborate .

Awaiting for your reply

Thanks