Getting data from server using asynctaskloader - android

here is my code for getting data from server.
public class POSDataCloud {
private static String SOAP_ACTION1 = "http://tempuri.org/GetDescription";
private static String NAMESPACE = "http://tempuri.org/";
private static String METHOD_NAME1 = "GetDescription";
private static String URL = "http://182.160.99.115:2080/webservice1.asmx?WSDL";
public String GetPOSData(int POSID)
{
String ret="";
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME1);
//request.addProperty("Id",POSID);
PropertyInfo property = new PropertyInfo();
{
property.name = "Id";
property.setNamespace(NAMESPACE);
property.type = PropertyInfo.STRING_CLASS;
property.setValue("3");
}
request.addProperty(property);
//Declare the version of the SOAP request
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
envelope.implicitTypes=true;
envelope.dotNet = true;
try
{
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
//this is the actual part that will call the webservice
androidHttpTransport.call(SOAP_ACTION1, envelope);
// Get the SoapResult from the envelope body.
SoapObject result = (SoapObject)envelope.bodyIn;
if(result != null)
{
ret=result.getProperty(0).toString();
}
else
{
ret="no response";
}
}
catch (Exception ex)
{
ex.printStackTrace();
ret=ex.getMessage();
}
return ret;
}
}
But I want to do it using asyncTaskLoader.How to do it?
Edit:Actually property.setValue is the PosId.how to pass posId in loadInBackground in asynctaskloader?I only need the implementation of loadInBackground method.i think it shold have posId parameter.But i can't get any example of asynctaskloader which takes parameter in loadInBackground method.Anybody helps me is greatly appreciated.

Related

Ksoap2 Trouble consuming Webservices on Android

I created a webServices in .net but there is a trouble when I am consuming it from my Android app. I noticed that the webservice is not getting the parameters I send from Android. however, I consumed it from the .net app and it works ok.
Note: with another webservice (webservicex/globalweather .asmx) my Android app works perfectly.
I put some spaces in the string URL variable because I can't publish more than 2 links
public class cargaDatosWS {
private static final String SOAP_ACTION = "http://www.esmerlinp.somee.com/getAccess";
private static final String METHOD_NAME = "getAccess";
private static final String NAMESPACE = "http://www.esmerlinp.somee.com";
private static final String URL = "http ://www. esmerlinp.somee .com/Registro.asmx";
public String getAcess(String Email,String Pwd){
String res=null;
SoapObject rpc;
rpc = new SoapObject(NAMESPACE, METHOD_NAME);
rpc.addProperty("email", Email);
rpc.addProperty("password", Pwd);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.bodyOut = rpc;
envelope.dotNet = true;
envelope.encodingStyle = SoapSerializationEnvelope.XSD;
HttpTransportSE androidHttpTransport= null;
try {
androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;
androidHttpTransport.call(SOAP_ACTION, envelope);
res = envelope.getResponse().toString();
}catch (Exception e){
System.out.println(e.getMessage());
res=e.getMessage();
}
return res;
}
}

Invoke web service from android application using soap object

I wrote a class called callSoap that invokes a web service (asmx) called test ,
the web method called GetData take integer as parameter and return list of strings
I defined
SOAP_ACTION
OPERATION_NAME
WSDL_TARGET_NAMESPACE
SOAP_ADDRESS
of my web service but the connection failed it and it did not return data
have anyone an idea about this ?
public final String SOAP_ACTION = "http://tempuri.org/GetData";
public final String OPERATION_NAME = "GetData";
public final String WSDL_TARGET_NAMESPACE = "http://tempuri.org/";
public final String SOAP_ADDRESS = "http://10.0.2.2:8216/test.asmx";
public String Call(int id)
{
SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,OPERATION_NAME);
PropertyInfo pi=new PropertyInfo();
pi.setName("id");
pi.setValue(id);
pi.setType(Integer.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();
}
}

Webservices in android

I am new to android. In my application I tried to call SOAP web services, in that I can't understand what is meant
for(SOAP_Action,OperationName,WSDL_TARGET_NAMESPACE,SOAP_ADDRESS). The following is my full code
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
TextView textView = new TextView(this);
setContentView(textView);
SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,
OPERATION_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
System.out.println("subbu="+request);
envelope.setOutputSoapObject(request);
HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
try
{
httpTransport.call(SOAP_ACTION, envelope);
Object response = envelope.getResponse();
textView.setText(response.toString());
}
catch (Exception exception)
{
textView.setText(exception.toString());
}
}
}
Can anybody explain what thats purpose for. Give some link from which I can get idea.
SOAP_ACTION / NAMESPACE and METHODS can be found in the WSDL file of the target webservice !
Here is a sample code to send a SOAP request to a webservice :
public class SoapRequest {
private static final String SOAP_ACTION = "xxx";
private static final String METHOD_NAME = "xxx";
private static final String NAMESPACE = "xxx";
private static final String URL = "url of the webservice";
public static SoapObject soap() throws IOException, XmlPullParserException {
SoapObject request = new SoapObject (NAMESPACE, METHOD_NAME);
/* Here you can add properties to your requests */
PropertyInfo pi1 = new PropertyInfo();
pi1.name = "xxx";
pi1.type = String.class;
request.addProperty(pi1, "xxx");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject soapResult = (SoapObject) envelope.bodyIn;
return soapResult;
}

Can not call C# .net Web Service method from Android client

I am trying to call a web service from Android client using the ksoap library.
Here is my android code
private static final String SOAP_ACTION = "http://tempuri.org/HelloWorld";
private static final String METHOD_NAME = "HelloWorld";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL = "http://192.16.0.230/WebService/Test.asmx";
TextView tv;
public void call()
{
try {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("name", "zawoad");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call(SOAP_ACTION, envelope);
String result = (String)envelope.getResponse();
tv.setText(result);
} catch (Exception e) {
tv.setText("exception :" + e.getLocalizedMessage());
}
}
And here is my web service method which is written in Test.asmx file
[WebMethod]
public string HelloWorld(string name)
{
return "Hello World" + name;
}
When the androidHttpTransport.call(SOAP_ACTION, envelope); line is executed it throws the following exception
org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope (position:START_TAG #2:44 in java.io.InputStreamReader#43e593c8)
Please help..
This is working code
private static final String SOAP_ACTION = "http://tempuri.org";
private static final String METHOD_NAME = "HelloWorld";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL = "http://192.16.0.230/WebService/Test.asmx?wsdl";
/*write ?wsdl only for local system testing*/
TextView tv;
public void call()
{
try {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("name", "zawoad");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL,20000);//Updated
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapPrimitive resultsRequestSOAP = (SoapPrimitive) envelope.getResponse();
String result = resultsRequestSOAP.toString();
tv.setText(result);
} catch (Exception e) {
tv.setText("exception :" + e.getLocalizedMessage());
}
}
The calling that you are performing will not happen.
what is the web service return type? We can pass the values and call that.

How to add header,username,password sharepoint webservice using ksoap in android

I am writing an Android application that will use the getlistitems() method of the lists.amx service in sharepoint 2010. I am using ksoap2-android to handle my soap messages. When I try to authenticate I get an xmlpullparser exception expected START_TAG... Why will the following code not authenticate to the sharepoint server?
private static final String SOAP_ACTION = "http://schemas.microsoft.com/sharepoint/soap/GetListItems";
private static final String METHOD_NAME = "GetListItems";
private static final String NAMESPACE = "http://schemas.microsoft.com/sharepoint/soap/";
private static final String URL = "http://www.domain.com/tr-TR/_vti_bin/Lists.asmx";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tv=(TextView)findViewById(R.id.tve);
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("listName", "Haberler");
request.addProperty("viewName", null);
request.addProperty("query", null);
request.addProperty("viewFields", null);
request.addProperty("rowLimit", "30");
request.addProperty("queryOptions", null);
request.addProperty("webID",null);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
// envelope.headerOut=new Element[1];
// envelope.headerOut[0]=buildAuthHeader();
String authentication = android.util.Base64.encodeToString("myusername:mypassword".getBytes(), android.util.Base64.NO_WRAP);
List<HeaderProperty> headers = new ArrayList<HeaderProperty>();
headers.add(new HeaderProperty("X-FORMS_BASED_AUTH_ACCEPTED","f" +authentication));
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;
try {
androidHttpTransport.call(SOAP_ACTION, envelope,headers);
SoapObject response = (SoapObject) envelope.getResponse();
tv.setText(response.toString());
Log.e("SONUC",response.toString());
} catch (Exception e1) {
e1.printStackTrace();
}
}
Don't send null values. Instead, add all the values and then try sending it.
Try to use NtlmTransport instead of HttpTransportSE. MayBe it works for you.

Categories

Resources