Ksoap2 Trouble consuming Webservices on Android - 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;
}
}

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.

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

SoapObject in android application

Here is some fragment of my android application code PerformDownload.java
public class PerformDownload {
private final String NAMESPACE = "http://tempuri.org/";
private final String URL = "http://10.0.2.2:4304/Service1.asmx";
public String GetContacts(String username) throws IOException, XmlPullParserException
{
// String result = null;
final String SOAP_ACTION = "http://tempuri.org/GetContacts";
final String METHOD_NAME = "GetContacts";
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("username",username);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true; // put this only if the web service is .NET one
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call(SOAP_ACTION, envelope);
KvmSerializable response= (KvmSerializable)envelope.bodyIn;
I am getting error on SoapObject,SoapSerializationEnvelope(SoapEnvelope.VER11); and so on.
Why the above code is not accessing soap protocol.

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