How to consume DataSet response from a SOAP service in Android? - android

I've been using SOAP based services in a lot of Android apps and they always work fine (string output usually). However, I've come across a service that accepts a DataSet and SQL Query as input and returns a DataSet as output.
From what I know of Android, there is no DataSet object type present. My question is, how do we utilize such a service in Android? Is it even possible to do so?
Here is a snapshot of the service:

Gladly for you, you can interface Android with ASP.NET so you can read the DataSET from your SOAP WebService
I'll give a snippet
public class CallSoap
{
public final String SOAP_ACTION = "http://tempuri.org/Add";
public final String OPERATION_NAME = "Add";
public final String WSDL_TARGET_NAMESPACE = "http://tempuri.org/";
public final String SOAP_ADDRESS = "http://yoururl/File.asmx";
public CallSoap()
{
}
public String Call(int a,int b)
{
SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,OPERATION_NAME);
PropertyInfo pi=new PropertyInfo();
pi.setName("a");
pi.setValue(a);
pi.setType(Integer.class);
request.addProperty(pi);
pi=new PropertyInfo();
pi.setName("b");
pi.setValue(b);
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();
}
}
First SOAP_ACTION = namespace as seen in figure 1+function name;
OPERATION_NAME = name of the web method;
WSDL_TARGET_NAMESPACE = namespace of the webservice;
SOAP_ADDRESS = absolute URL of the webservice;

Related

Getting data from server using asynctaskloader

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.

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

android send data to a .net webservice

I am trying to create a android app to send text and photos to .net webservice. I have functions in my webservice. one of them gets a dummy name(I created this to check if I can make a connection) and the other one is to insert some data into DB. I want to post my work to get help.
private final String NAMESPACE = "http://methodoor.com/";
//webservice is working, you can check it online
private final String URL = "http://servicing2.rotanet.com.tr/service.asmx";
private final String SOAP_ACTION = "http://methodoor.com/checkupservice/SendData";
private final String METHOD_NAME = "SendData";
//Create request
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("containerId",1);
.........
.........
request.addProperty("sFileID","asd");
request.addProperty("userId",1);
//Create envelope
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
//Set output SOAP object
envelope.setOutputSoapObject(request);
//Create HTTP call object
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
//Invole web service
androidHttpTransport.call(SOAP_ACTION, envelope);
//Get the response
SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
//Assign it to fahren static variable
fahren = response.toString();
} catch (Exception e) {
}
My problem is, I am not sure if this is the correct way to pass data to webservice. it doesnt crash or gives any error message. It just doesnt insert into the DB
here you go..make sure to check spelling of each tag in your service, method name and path of your service..
public SoapObject soap(String METHOD_NAME, String SOAP_ACTION, String NAMESPACE, String URL,String IP,String SERVICEPATH) throws IOException, XmlPullParserException
{
abc.allowAllSSL();
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); //set up request
//request.addProperty("iTopN", "5"); //variable name, value. I got the variable name, from the wsdl file!
request.addProperty("UserId", login);
request.addProperty("Password", password);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); // put all required data into a soap
envelope.dotNet = true;
envelope.setOutputSoapObject(request); // prepare request
envelope.bodyOut = request;
Log.d("ENVELOPE",""+"Coming3");
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
//androidHttpTransport.
androidHttpTransport.call(SOAP_ACTION, envelope);
Log.d("ENVELOPE",""+envelope.bodyIn);
SoapObject result = (SoapObject) envelope.bodyIn; // get response
Log.d("ENVELOPE",""+envelope.bodyIn);
SoapObject responseBodyRaw,responseBody,tableRow;
return result;
}
Here is parameter details
private String NAMESPACE = "http://tempuri.org/";
private String SOAP_ACTION = "http://tempuri.org/UserProfile";
private String METHOD_NAME = "UserProfile";
private String URL="https://172.17.60.15/HostingService/PhoneForService.asmx";
//private String URL="https://172.19.2.250/testService/phone.asmx";
private String SERVICEPATH="/HostingService/PhoneForService.asmx";
I hope would be helpful for you

Issue with sending data to a webservice, with ksoap

Good evening,
I need your help.
Until now, using my webservice to withdraw data, there was no problem.
Even to receive the data, I have to send some. Example: Login.
However, now I want to send data to the webservice, and it will only return "true or false".
I know I have the necessary data, but does not do what is supposed to do.
That is, the method I am invoking, it needs to receive data, and with these data it does the update in the database.
I know which works manually, directly on webservice.
what might be wrong?
Below is the code:
After insert the data on the app on android, when i click on a button, do this:
The message on the end, is the way that i know that i send real data:
try
{
newpassword = newPass;
Abreviatura = (EditText)findViewById(R.id.txtAbreviatura);
newabreviatura = Abreviatura.getText().toString();
Nome = (EditText)findViewById(R.id.txtNome);
newnome = Nome.getText().toString();
User = (EditText)findViewById(R.id.txtUsername);
newusername = User.getText().toString();
rslt="START";
Caller c=new Caller(); c.newNome = newnome;
c.newUser = newusername; c.newPass = newpassword;
c.newAbrev = newabreviatura; c.oldusername = oldusername;
c.ad=ad;
c.join(); c.start();
while(rslt=="START") {
try {
Thread.sleep(10);
}catch(Exception ex) {
}
}
ad.setTitle("Alteração:");
ad.setMessage(BIQActivity.comando + ";" + newnome + ";" + newpassword + ";" + newabreviatura + ";" + newusername + ";" + oldusername);
ad.show();
}catch(Exception ex)
{
}
That function, uses this peace of code, to send data to the next code:
csup=new CallSoapUpdatePerfil();
String resp=csup.CallUpdatePerfil(newUser, newNome, newPass, newAbrev, ldusername);
Perfil.rslt = resp;
Finally, this is the code that send's the data to the webservice:
public class CallSoapUpdatePerfil {
public final String SOAP_ACTION = "http://tempuri.org/UpdatePerfil";
public final String OPERATION_NAME = "UpdatePerfil";
public final String WSDL_TARGET_NAMESPACE = "http://tempuri.org/";
public final String SOAP_ADDRESS = "http://10.0.2.2:80/BIQAndroid/BIQAndroid.asmx";
public String CallUpdatePerfil(String User, String Pass, String Nome, String Abrev, String oldusername)
{
SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,OPERATION_NAME);
PropertyInfo pi=new PropertyInfo();
pi.setName("User");
pi.setValue(User);
pi.setType(String.class);
request.addProperty(pi);
pi=new PropertyInfo();
pi.setName("Pass");
pi.setValue(Pass);
pi.setType(String.class);
request.addProperty(pi);
pi=new PropertyInfo();
pi.setName("Abrev");
pi.setValue(Abrev);
pi.setType(String.class);
request.addProperty(pi);
pi=new PropertyInfo();
pi.setName("Nome");
pi.setValue(Nome);
pi.setType(String.class);
request.addProperty(pi);
pi=new PropertyInfo();
pi.setName("oldusername");
pi.setValue(oldusername);
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();
}
}
If anyone can help... Regards.
I already find the error. The error is about the name of parameter of webservice. :s
Done.
Thanks anyway.

Android: soap primitive error

I am having some issues with accessing a web service. Getting ClassCastException Error. Consider a scenario that I am trying to access a method of a web-service and the webservice is supposed to return two strings (Lets say String1 and String2). Moreover, I have to provide or pass two parameters (lets say Parameter 1 and Parameter 2 where Parameter 1 should be integer and Parameter 2 should be String) Here is my code
public class MyWebService extends Activity {
private static final String SOAP_ACTION ="http://www.mywebsite.com/myMethod";
private static final String METHOD_NAME = "MyMethod";
private static final String NAMESPACE = "http://www.myNamespace/";
private static final String URL = "http://mysession.com/myservice.asmx?WSDL";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
PropertyInfo pi = new PropertyInfo();
pi.setName("Parameter 1");
pi.setValue(1);
pi.setType(pi.INTEGER_CLASS);
request.addProperty(pi);
PropertyInfo pi2 = new PropertyInfo();
pi2.setName("Parameter 2");
pi2.setValue("Any string");
pi2.setType(pi2.STRING_CLASS);
request.addProperty(pi2);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject result=(SoapObject)envelope.getResponse();
String string1=result.getProperty(0).toString();
String string2=result.getProperty(1).toString();
} catch (Exception e) {
e.printStackTrace();
}
}
}
This is the exception I am getting
java.lang.ClassCastException: org.ksoap2.serialization.SoapPrimitive
Can anyone tell me if I am doing something wrong here..
Thanks
Try this,
SoapPrimitive result= (SoapPrimitive)envelope.getResponse();
OR
Object result= (Object)envelope.getResponse();
instead of
SoapObject result=(SoapObject)envelope.getResponse();
Try this:
SoapObject request = new SoapObject(SOAP_NAMESPACE,SOAP_METHOD);
request.addProperty("name", abcd);
request.addProperty("age", 30);

Categories

Resources