provide security for header in ksoap2 in android - android

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());
}
}
}

This is Working for me... Try this.
public static Element buildAuthHeader() {
Element headers[] = new Element[1];
headers[0]= new Element().createElement("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "Security");
headers[0].setAttribute(null, "mustUnderstand", "1");
Element security=headers[0];
//user token
Element usernametoken = new Element().createElement(security.getNamespace(), "UsernameToken");
usernametoken.setAttribute("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd", "Id", "UsernameToken-14CBAE357AC169AFA614664925178422");
//username
Element username = new Element().createElement(security.getNamespace(), "Username");
username.addChild(Node.TEXT, HttpConstant.REQ_HEADER_USERNAME);
usernametoken.addChild(Node.ELEMENT,username);
// password
Element password = new Element().createElement(security.getNamespace(), "Password");
password.setAttribute(null, "Type", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText");
password.addChild(Node.TEXT, HttpConstant.REQ_HEADER_PASSWORD);
usernametoken.addChild(Node.ELEMENT,password);
headers[0].addChild(Node.ELEMENT, usernametoken);
return headers[0];
}

Related

How to send request post method in svc(soap) service in android?

I don't know how to send request in post method in soap service.Please someone help me to resolve this.
Here is my code so far.
//Code
String NAMESPACE = "http://tempuri.org/";
String METHOD_NAME = "Login";
String SOAP_ACTION = "http://tempuri.org/Login";
String URL = "http://hostname/AllServices.svc/Login";
protected void soap() {
// TODO Auto-generated method stub
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
// Set all input params
request.addProperty("sapcode", "3232323");
request.addProperty("password", "3232323");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER12);
// Enable the below property if consuming .Net service
envelope.dotNet = true;
envelope.encodingStyle = SoapEnvelope.ENC;
envelope.setAddAdornments(false);
envelope.implicitTypes = false;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
envelope.headerOut = new Element[1];
envelope.headerOut[0] = buildAuthHeader();
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject response = (SoapObject) envelope.getResponse();
Log.i("response", response.getProperty(0).toString());
// response.getProperty(0).toString();
} catch (Exception e) {
e.printStackTrace();
}
}
private Element buildAuthHeader() {
Element h = new Element().createElement(NAMESPACE, "AuthHeader");
Element username = new Element().createElement(NAMESPACE, "User Name");
username.addChild(Node.TEXT, "tech");
h.addChild(Node.ELEMENT, username);
Element pass = new Element().createElement(NAMESPACE, "Password");
pass.addChild(Node.TEXT, "tech#001");
h.addChild(Node.ELEMENT, pass);
return h;
}
Basic Header Authentication:
Every method call from the API requires basic header authentication
User Name:
Password:
Method Type: POST
Return type is json format.
try {
// Build JSON string
JSONStringer loginCredentials = new JSONStringer().object()
.key("sapcode").value(userNameSend).key("password")
.value(passwordSend).endObject();
JSONObject jsonObj = new ServerResponse(
Urlgenerator.loginCheck()).getJSONObjectfromURL(
RequestType.POST, loginCredentials);
if (jsonObj != null) {
JSONObject loginObj = jsonObj.getJSONObject("Login");
if (loginObj != null) {
String errorcode = loginObj.getString("errorcode");
final String result = loginObj.getString("result");
if (errorcode.equalsIgnoreCase("0")) {
Utils.updateSharedPreference("remember", "true");
Utils.updateSharedPreference("sapcode",
userNameSend);
startActivity(new Intent(LoginScreen.this,
HomeScreen.class));
finish();
} else {
runOnUiThread(new Runnable() {
#Override
public void run() {
// TODO Auto-generated method stub
ToastUtils.displayToast(
ToastTypeEnum.ALERT_TOAST, result,
Toast.LENGTH_SHORT);
}
});
}
}
}
pDialog.dismiss();
} catch (Exception e) {
pDialog.dismiss();
}

getting error while calling soap request in android?

I am using Ksoap2 android assembly 2.4 in my android application.I am try to call the web service by using soap.But I am getting the error at transport.call(soapAction, envelop); this line.
LOGCaT:
org.xmlpull.v1.XmlPullParserException: expected: END_TAG {http://schemas.xmlsoap.org/soap/envelope/}Body (position:END_TAG </{http://schemas.xmlsoap.org/soap/envelope/}soap:Fault>#1:301 in java.io.InputStreamReader#41743310)
And Here my code is:
String url = "http://192.168.56.1:8080/CxfWebservice/webservices/Calculator";
// String namespace = "http://localhost:8080/wsdl";
String namespace = "http://192.160.59.1:8080/wsdl";
String methodname = "sum";
public static void SoapOperation(String url, String method_name,
String name_space) throws Exception {
String soapAction = name_space + method_name;
SoapObject request = new SoapObject(name_space, method_name);
PropertyInfo p = new PropertyInfo();
p.setName("arg0");
p.setValue(5);
p.setType(Integer.TYPE);
PropertyInfo p1 = new PropertyInfo();
p1.setName("arg1");
p1.setValue(15);
p1.setType(Integer.TYPE);
request.addProperty(p );
request.addProperty(p1);
SoapSerializationEnvelope envelop = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelop.setOutputSoapObject(request);
envelop.dotNet = true;
HttpTransportSE transport = new HttpTransportSE(url);
transport.debug = true;
transport.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
transport.call(soapAction, envelop);
String xml = transport.responseDump;
System.out.println("the response xml is:"+xml);
}
above is my code with please give me a solution for this.
Here is an example. Use this code
public void InteractWithWebService() {
try {
final String URL = con.getResources().getString(R.string.URL);
final String NameSpace = con.getResources().getString(
R.string.NAMESPACE);
final String MethodName = "sum";
final String SOAP_ACTION = con.getResources().getString(
R.string.SOAP_ACTION)
+ MethodName;
SoapObject Request = new SoapObject(NameSpace, MethodName);
Request.addProperty("param_name", Object_name.getText().toString()
.trim());
Request.addProperty("param_name", Object_name.getText().toString()
.trim());
SoapSerializationEnvelope soapEnvelop;
soapEnvelop = new SoapSerializationEnvelope(SoapEnvelope.VER11);
soapEnvelop.dotNet = true;
soapEnvelop.setOutputSoapObject(Request);
HttpTransportSE htp = new HttpTransportSE(URL);
htp.call(SOAP_ACTION, soapEnvelop);
// SoapObject response;
SoapPrimitive resultString = (SoapPrimitive) soapEnvelop
.getResponse();
if (resultString != null) {
status = Integer.parseInt(resultString.toString());
}
} catch (Exception ex) {
status = -1;
}
}
Add these lines in your strings file
<string name="NAMESPACE">http://tempuri.org/</string>
<string name="URL">http://Your_Localhost_address/Name_of_Service.svc</string>
<string name="SOAP_ACTION">http://tempuri.org/IName_of_Service/</string>

Webservice call return java.net.SocketTimeoutException: Transport endpoint is not connected

I'm trying to get the data from the ASMX web service. Ihave used the code from here and used its ConvertWaight web service but its not working.
Its showing me error java.net.SocketTimeoutException: Transport endpoint is not connected. Ihave added the network permission but still got this error.
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
Please help me with this any example code will be really helpful.
My web service accept the NSDictionary in the iOS. Like this...
{
memberDetails = {
DeviceName = "iPhone Simulator";
DeviceToken = 951fc5a77184ds1a17474256759a34e03d31b708a0358v742df38bb3cc845ds4;
EmailAddress = "user#org.com";
IsRemember = True;
Password = "123456789";
};
}
So in android i have tried to pass the HasMap to the webservice
here is the my web service if it help
POST /service/xxx.asmx HTTP/1.1
Host: www.xxx.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/SelectByEmailAndPassword"
<?xml version="1.0" encoding="utf-8"?>
<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/">
<soap:Body>
<SelectByEmailAndPassword xmlns="http://tempuri.org/">
<memberDetails>
<EmailAddress>string</EmailAddress>
<Password>string</Password>
<DeviceToken>string</DeviceToken>
<DeviceName>string</DeviceName>
<IsRemember>boolean</IsRemember>
</memberDetails>
</SelectByEmailAndPassword>
</soap:Body>
</soap:Envelope>
And Here is my code to call the web service
public String Call(String deviceName, String deviceToken, String emailAddress, String isRemember, String password)
{
SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,OPERATION_NAME);
PropertyInfo pi=new PropertyInfo();
//Create a HashMap
Map <String,String> memberDetails = new HashMap<String,String>();
//Put data into the HashMap
memberDetails.put("DeviceName","android Simulator");
memberDetails.put("DeviceToken","951fc5a77184ds1a17474256759a34e03d31b708a0358v742df38bb3cc845ds4");
memberDetails.put("EmailAddress","user#org.com");
memberDetails.put("IsRemember","True");
memberDetails.put("Password","123456789");
pi.setName("memberDetails");
pi.setValue(memberDetails.toString());
pi.setType(String.class);
request.addProperty(pi);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
Object response=null;
try
{
httpTransport.call(SOAP_ACTION, envelope);
response = envelope.getResponse();
}
catch (Exception exception)
{
response=exception.toString();
}
return response.toString();
}
}
I check link. Than I create Testconnection project. All webservice call must be on the background thread. Could you create I thread and run your target in it?
private void getResult()
{
new Thread(){
public void run()
{
WebserviceCall com = new WebserviceCall();
// Initialize variables
final String weight = "18000";
String fromUnit = "Grams";
String toUnit = "Kilograms";
//Call Webservice class method and pass values and get response
final String aResponse = com.getConvertedWeight("ConvertWeight", weight, fromUnit, toUnit);
//Alert message to show webservice response
button.post(new Runnable() {
#Override
public void run() {
Toast.makeText(getApplicationContext(), weight+" Gram= "+aResponse+" Kilograms",
Toast.LENGTH_LONG).show();
}
});
Log.i("AndroidExampleOutput", "----"+aResponse);
}
}.start();
}
And than my web service class samely in link;
public class WebserviceCall {
String namespace = "http://www.webserviceX.NET/";
private String url = "http://www.webservicex.net/ConvertWeight.asmx";
String SOAP_ACTION;
SoapObject request = null, objMessages = null;
SoapSerializationEnvelope envelope;
AndroidHttpTransport androidHttpTransport;
WebserviceCall() {
}
/**
* Set Envelope
*/
protected void SetEnvelope() {
try {
// Creating SOAP envelope
envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
//You can comment that line if your web service is not .NET one.
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
androidHttpTransport = new AndroidHttpTransport(url);
androidHttpTransport.debug = true;
} catch (Exception e) {
System.out.println("Soap Exception---->>>" + e.toString());
}
}
// MethodName variable is define for which webservice function will call
public String getConvertedWeight(String MethodName, String weight,
String fromUnit, String toUnit)
{
try {
SOAP_ACTION = namespace + MethodName;
//Adding values to request object
request = new SoapObject(namespace, MethodName);
//Adding Double value to request object
PropertyInfo weightProp =new PropertyInfo();
weightProp.setName("Weight");
weightProp.setValue(weight);
weightProp.setType(double.class);
request.addProperty(weightProp);
//Adding String value to request object
request.addProperty("FromUnit", "" + fromUnit);
request.addProperty("ToUnit", "" + toUnit);
SetEnvelope();
try {
//SOAP calling webservice
androidHttpTransport.call(SOAP_ACTION, envelope);
//Got Webservice response
String result = envelope.getResponse().toString();
return result;
} catch (Exception e) {
// TODO: handle exception
return e.toString();
}
} catch (Exception e) {
// TODO: handle exception
return e.toString();
}
}
}

How to sign SOAP Message used ksoap2 library whit certificate x509 on Android app?

How I can sign my SOAP Message (for example UserToken in Header) used ksoap2 library for SOAP message and certificate x509 on Android app?
I can send this message:
<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>
<soapenv:Body>
<ns1:add xmlns:ns1="http://service.rampart.tutorial">
<ns1:a>4</ns1:a>
<ns1:b>6</ns1:b>
</ns1:add>
</soapenv:Body></soap:Envelope>
used this code:
public class AndroidWSClientActivity extends Activity {
private static final String SOAP_ACTION = "https//service.rampart.tutorial/SecureService";
private static final String SAY_HELLO = "SimpleHelo";
private static final String RETURN_SUMMA = "add";
private static final String NAMESPACE = "http://service.rampart.tutorial";
private static final String URL = "https://192.168.1.18:8443/axis2/services/SecureService?wsdl";
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
SoapObject request = new SoapObject(NAMESPACE, RETURN_SUMMA);
request.addProperty( "a", 1);
request.addProperty( "b", 3);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
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,"apache");
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, "password");
usernametoken.addChild(Node.ELEMENT, pass);
envelope.headerOut = header;
envelope.setOutputSoapObject(request);
try {
HttpTransportSE ht = new HttpTransportSE(URL);
ht.call(SOAP_ACTION, envelope);
SoapObject result = (SoapObject) envelope.bodyIn;
TextView tv = new TextView(this);
if(result != null)
{
tv.setText(result.getProperty(0).toString());
}
else
{
Toast.makeText(getApplicationContext(), "No Response", Toast.LENGTH_LONG).show();
}
setContentView(tv);
} catch (Exception e) {
e.printStackTrace();
}
}
}
How send this message for example:
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" soapenv:mustUnderstand="true">
<wsu:Timestamp xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="Timestamp-13121387">
<wsu:Created>2008-03-27T15:29:37.454Z</wsu:Created>
<wsu:Expires>2008-03-27T15:34:37.454Z</wsu:Expires>
</wsu:Timestamp>
<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#" Id="Signature-29744585">
<ds:SignedInfo>
<ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
<ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
<ds:Reference URI="#Id-14293164">
<ds:Transforms>
<ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
</ds:Transforms>
<ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
<ds:DigestValue>KELVaFQ7RnfPIUMAU9q4D/5rGOU=</ds:DigestValue>
</ds:Reference>
<ds:Reference URI="#Timestamp-13121387">
<ds:Transforms>
<ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
</ds:Transforms>
<ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
<ds:DigestValue>7t9QUVXRJ0yTS+84OSfsH7pAguM=</ds:DigestValue>
</ds:Reference>
</ds:SignedInfo>
<ds:SignatureValue> ...ZL1FMFxsUvwBU2ZYYbNxGu/uJceG1i4uSPd6+BSiqYWal ...</ds:SignatureValue>
<ds:KeyInfo Id="KeyId-24374386">
<wsse:SecurityTokenReference xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="STRId-8406772">
<wsse:KeyIdentifier EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary"
ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509SubjectKeyIdentifier">
ins6410Q1skpvizn19AUk7dC6rI=
</wsse:KeyIdentifier>
</wsse:SecurityTokenReference>
</ds:KeyInfo>
</ds:Signature>
</wsse:Security>
</soapenv:Header>
<soapenv:Body xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="Id-14293164">
<ns1:add xmlns:ns1="http://service.rampart.tutorial">
<ns1:a>3</ns1:a>
<ns1:b>4</ns1:b>
</ns1:add>
</soapenv:Body>
link to tutorials or samples would be helpful.
Thanks!

How to get subfolders from listview on clicking itemclick using .net web services in Android?

I am trying to get subfolders after clicking on on item in list using .net web services. Please suggest. Thanks
public void Treedata(){
try {
SoapObject datarequest = new SoapObject(NAMESPACE, TREEDATA_METHOD);
datarequest.addProperty("UserID", 1);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(datarequest);
Log.i("LoginDetail", "UserID " + 1);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;
androidHttpTransport.call(SOAP_ACTION_TREEDATA, envelope);
SoapObject dataresponse = (SoapObject)envelope.getResponse();
Log.i("myData", dataresponse.toString());
datalist = new String[dataresponse.getPropertyCount()];
for(int i=0; i< dataresponse.getPropertyCount(); i++)
datalist[i] = dataresponse.getProperty(i).toString();
treedata = (ListView)findViewById(R.id.treedata);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, datalist);
treedata.setAdapter(adapter);
treedata.setOnItemClickListener(new OnItemClickListener()
{
#Override
public void onItemClick(AdapterView<?> arg0, View v,int position, long id) {
// TODO Auto-generated method stub
// What to do here??? So that sub folders can get into next activity.
Intent intent = new Intent(getApplicationContext(), Files_Folders_Activity.class);
startActivity(intent);
}
});
}
}
}
Next Activity:
public void subfolderTreedata(){
try {
SoapObject subfolderrequest = new SoapObject(NAMESPACE, SUBFOLDERTREEDATA_METHOD);
subfolderrequest.addProperty("FolderID", 13002); //13002 is folderID how can I get multiple Id Dynamically?
subfolderrequest.addProperty("UserID", 1);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(subfolderrequest);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;
androidHttpTransport.call(SOAP_ACTION_SUBFOLDERTREEDATA , envelope);
SoapObject dataresponse = (SoapObject)envelope.getResponse();
Log.i("subfoldersData", dataresponse.toString());
// if(UserID || FolderID == dataresponse){ //How to get dynamic userId and Password right now I am having static 1 for user password authentication, what to do for multiple authentication.
subfolderslist = new String[dataresponse.getPropertyCount()];
for(int i=0;i< dataresponse.getPropertyCount(); i++)
subfolderslist[i] = dataresponse.getProperty(i).toString();
subfolderstreedata = (ListView)findViewById(R.id.subfolderstreedata);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, subfolderslist);
subfolderstreedata.setAdapter(adapter);
My Web Services:
Host: ***.***.*.*
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/TreeDataSubFolder"
<?xml version="1.0" encoding="utf-8"?>
<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/">
<soap:Body>
<TreeDataSubFolder xmlns="http://tempuri.org/">
<FolderID>string</FolderID>
<UserId>string</UserId>
</TreeDataSubFolder>
</soap:Body>
</soap:Envelope>
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<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/">
<soap:Body>
<TreeDataSubFolderResponse xmlns="http://tempuri.org/">
<TreeDataSubFolderResult>
<FileFolderDetails>
<ID>int</ID>
<Name>string</Name>
<SubjectType>string</SubjectType>
</FileFolderDetails>
<FileFolderDetails>
<ID>int</ID>
<Name>string</Name>
<SubjectType>string</SubjectType>
</FileFolderDetails>
</TreeDataSubFolderResult>
</TreeDataSubFolderResponse>
</soap:Body>
</soap:Envelope>
I just wanted to confirm How can I send FOLDERID and USERID same time to get subfolders and retrieve data from listitem.
Heres answer:
public class TreeDataActivity extends Activity implements OnItemClickListener {
private ListView datalist;
private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL = "http://192.168.1.5/InterLogicsMobile/InterLogics.asmx";
private static final String SOAP_ACTION = "http://tempuri.org/TreeData";
private static final String TreeDataMethod = "TreeData";
private String[] firstlist;
String FolderID = null;
String ID;
String FolderName;
String ParentID;
String CreatedBy;
// List<IconSetter> rowItems;
// public static final Integer[] images = { R.drawable.folder_icon,};
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
setContentView(R.layout.treedata);
TreeData();
}
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
ID = (String) datalist.getItemAtPosition(arg2);
//FolderName = (String) datalist.getItemAtPosition(arg2);
Intent intent = new Intent(TreeDataActivity.this,TreeDataSubFolderActivity.class);
intent.putExtra("ID",ID );
//intent.putExtra("FolderName",FolderName );
startActivity(intent);
}
private void TreeData() throws NullPointerException{
try {
SoapObject request = new SoapObject(NAMESPACE, TreeDataMethod);
request.addProperty("UserID", 1);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject list = (SoapObject)envelope.getResponse();
System.out.print(list);
firstlist = new String[list.getPropertyCount()];
for(int i=0;i< list.getPropertyCount();i++){
/*rowItems = new ArrayList<IconSetter>();
IconSetter item = new IconSetter(images[0],FolderName[1],ID[2]);
rowItems.add(item);*/
SoapObject result = (SoapObject)list.getProperty(i);
ID = result.getProperty(0).toString();
FolderName = result.getProperty(1).toString();
ParentID = result.getProperty(2).toString();
CreatedBy = result.getProperty(3).toString();
System.out.println(ID);
System.out.println(FolderName);
System.out.println(ParentID);
System.out.println(CreatedBy);
SoapPrimitive Record =(SoapPrimitive) result.getProperty(1);
Log.i("Record", Record.toString());
firstlist[i] = result.getPropertyAsString(0).toString();
// firstlist[i] = result.getPropertyAsString(1).toString();
datalist = (ListView) findViewById(R.id.first_list);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, firstlist);
datalist.setAdapter(adapter);
datalist.setOnItemClickListener(this);
}
}
catch (Exception e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(), " NullPointerException " + e
+ "Do Something", Toast.LENGTH_LONG).show();
}finally{
}
}
}

Categories

Resources