I want to call wsdl file in android using ksoap2 library. I have to provide security for header in soap envelope. I make below type of soap request which are as given below.
<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<soap:Header>
<wsse:Security
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" soap:mustUnderstand="1">
<wsse:UsernameToken
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:Username>cbrown</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">welcome</wsse:Password></wsse:UsernameToken>
</wsse:Security>
</soap:Header>
<soap:Body xmlns:ns1="http://xmlns.oracle.com/bpel/aubi/mobile/Worklist">
<ns1:WorklistRetrievalREQ>
<ns1:WorklistType>HR_OFFER</ns1:WorklistType>
<ns1:Status>TODO</ns1:Status>
<ns1:Mode/>
</ns1:WorklistRetrievalREQ>
</soap:Body>
</soap:Envelope>
but I have no any idea that how to provide security in envelope header (). So, Please help for code.
Thanks in advance...
finally I got my answer of my question.
public class SOAP_WebService extends Activity
{
private final String NAMESPACE = "http://ws.simple/";
private final String URL = "http://10.0.2.2/SimpleWebservice/simple";
private final String SOAP_ACTION = "http://ws.simple/getString";
private final String METHOD_NAME = "getString";
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.soap_webservice);
Button btnClick = (Button) findViewById(R.id.btnClick);
btnClick.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
callWebservice();
}
});
}
public void callWebservice()
{
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
PropertyInfo weightProp =new PropertyInfo();
weightProp.name = "arg0";
weightProp.setValue("rajan");
request.addProperty(weightProp);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
// create header
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.setAttribute(null, "Id", "UsernameToken-1");
header[0].addChild(Node.ELEMENT,usernametoken);
Element username = new Element().createElement(null, "n0:Username");
username.addChild(Node.IGNORABLE_WHITESPACE,"CBROWN");
usernametoken.addChild(Node.ELEMENT,username);
Element pass = new Element().createElement(null,"n0:Password");
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, "welcome");
usernametoken.addChild(Node.ELEMENT, pass);
// add header to envelope
envelope.headerOut = header;
Log.i("header", "" + envelope.headerOut.toString());
envelope.dotNet = false;
envelope.bodyOut = request;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
Log.i("bodyout", "" + envelope.bodyOut.toString());
try
{
androidHttpTransport.debug = true;
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
Log.i("myApp", response.toString());
}
catch (SoapFault e)
{
e.printStackTrace();
}
catch (Exception e)
{
e.printStackTrace();
Log.d("Exception Generated", ""+e.getMessage());
}
}
}