I tested calling a soap 12 webservices with ksoap2.
I used this code to call the webservice:
SoapObject request = new SoapObject(NAMESPACE, NAME);
request.addProperty("id", ID);
request.addProperty("name", "test#test.de");
request.addProperty("pw", "password");
request.addProperty("listid", 501);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
envelope.setOutputSoapObject(request);
AndroidHttpTransport client = new AndroidHttpTransport(URL);
try {
client.call(NAMESPACE + NAME, envelope);
Object response = envelope.getResponse();
} catch (IOException e) {
Log.e(getClass().getSimpleName(), "IO Problem", e);
} catch (XmlPullParserException e) {
Log.e(getClass().getSimpleName(), "Parser Problem", e);
}
I now get the following exception:
org.xmlpull.v1.XmlPullParserException:expected: START_TAG {http://www.w3.org/2001/12/soap-envelope}Envelope (position:START_TAG <{http://schemas.xmlsoap.org/soap/envelope/}soapenv:Envelope>#1:114 in java.io.InputStreamReader#44f28a80)
Is this a problem of the server response or is there something wrong in my code so far? It seems that other users have the same problem. If I change the Envelope to SoapEnvelope.VER11 I get a step further (I get an access denied response from the soap server probably because of a wrong URL) maybe there is additional info missing to create a VER12 envelope.
Have you tried the various options for your envelope to see what the services expects?
E.g. you can set
envelope.dotNet = true;
envelope.headerOut = security; // this is an Element[] created before
envelope.encodingStyle = SoapEnvelope.ENC;
envelope.setAddAdornments(false);
envelope.implicitTypes = false;
and a bunch more. Check out the javadoc?
Also make sure to use the latest release of the ksoap2-android project to get a bunch of fixes that are not in the normal sourceforge project.
What I did to make this work was use version 11, and it worked fine for me :-)
// Request model
SoapObject request = new SoapObject(namespace, Metodo);
// Envelop model
SoapSerializationEnvelope sobre = new SoapSerializationEnvelope(SoapEnvelope.VER11);
sobre.dotNet = true;
sobre.setOutputSoapObject(request);
// Transport model
HttpTransportSE transporte = new HttpTransportSE(url);
// Let's call it :)
transporte.call(accionSoap, sobre);
//Result
SoapPrimitive resultado = (SoapPrimitive) sobre.getResponse();
tv.setText("" + resultado.toString());
My variables:
private static final String accionSoap = "http://tempuri.org/ServicioAndroid";
private static final String Metodo = "ServicioAndroid";
private static final String namespace = "http://tempuri.org/";
private static final String url = "http://192.168.1.33/AutoEPOC_H/WS/WSAutoEPOC.asmx";
This Web Service was created usin dotNet. You can check your method, action, namespace and URL by running your Web Service using IIS.
If you understand Spanish, you can check these links:
http://www.youtube.com/watch?v=_MMByNiwqMc
http://programa-con-google.blogspot.com/2010/12/android-como-consumir-un-servicio-web.html
I hope this helps!
I use ksoap2 ver11 only... still it gives me an expected start_tag error when I use it on another server other than localhost.
My webservices are hosted perfectly by my company's server but it gives this expected start tag error in Android 2.2 emulator and displays nothing (null error) in toast.
I am not sure but it can be the 'NetworkOnMainThread' exception in phone(Android 4.0).
Try VR11 and replace your
Object response = envelope.getResponse();
with
SoapObject reponse=(SoapObject)envelope.getResponse();
I had the same problem, I kept getting an exception “Permission Denied” from envelop.getResponse.
I assumed something was wrong with my SOAP request and tried a number of changes to the envelop. Eventually after looking through some other boards I realized I needed an additional permission for android to allow this.
So add the following permission to your Android app's manifest.
<uses-permission android:name="android.permission.INTERNET">
Related
I am having trouble to comunicate with my web service using ksoap for android. The idea is to receive a JSON as String and then do some parsing on this string. I opened my web service form Eclipse web services explorer and everything seems to be working fine on server side, parameters provided to the request are correct.
My error:
SoapFault - faultcode: 'soapenv:Server' faultstring: '3' faultactor: 'null' detail: org.kxml2.kdom.Node#b75ddd60
SOAP fault codes says that its a server error, but as I said above it works fine form Eclipse web services explorer.
My code:
private static final String method_get_quest_by_id = "getQuestionsById";
private static final String NAMESPACE = "http://surveys.services.backend.capi.ateam";
private static final String retirieveQuestById = NAMESPACE
+ method_get_quest_by_id;
private static String url = "http://ec2-184-73-10-139.compute-1.amazonaws.com:8080/Services/services/SurveyService";
try{
SoapObject request = new SoapObject(NAMESPACE,method_get_quest_by_id);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
request.addProperty("userName", userName);
request.addProperty("password", pass);
request.addProperty("id", id);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(url);
androidHttpTransport.call(retirieveQuestById, envelope);
Object result = envelope.getResponse();
resultString= result.toString();
} catch (Exception E) {
E.printStackTrace();
}
Im working on android 2.2.
Can someone please help me? I've been stuck on this for a couple of days now...
Thank you
Finally I found the reason for the problem. I was passing "id" as a parameter name when it should have been "identifier".
Took a long time to spot the problem probably because the faultstring was not of much help.
My guess is that the faultstring = "3" indicates a problem with parameter number 3.
I want to call web service running in Microsoft Dynamics nav ERP i am using ksoap2 library but problem is every time i run my application it throws
java.net.ConnectException: localhost/127.0.0.1:7047 - Connection refused
Microsoft Dynamics nav is using NTLM authentication may that is the problem, please give any suggestion to solve it.
Thanks in advance.
My code is
String namespace = "urn:microsoft-dynamics-schemas/codeunit/NavisionWS";
String url = "http://localhost:7047/DynamicsNAV/WS/Codeunit/NavisionWS";
String soap_action = "urn:microsoft-dynamics-schemas/codeunit/NavisionWS:GetLoginInfo";
String method_name = "GetLoginInfo";
try
{
SoapObject request = new SoapObject(namespace, method_name);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE transport = new HttpTransportSE(url);
transport.call(soap_action, envelope); // Receive Error here!
SoapObject result = (SoapObject) envelope.getResponse();
great = result.toString();
}
catch (Exception e)
{
e.printStackTrace();
great = e.toString();
Toast.makeText(this, great, Toast.LENGTH_LONG).show();
}
Use IP Address instead of Localhost to connect to webservice from Android
Have you added <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> to your manifest?
I am using ksoap to connect to CrmDiscoveryService on Android, here comes the problem:
SoapFault - faultcode: 'soap:server' faultstring: 'Server was unable to process request.' faultactor: 'null' detail: org.kxml2.kdom.Node#4061bd00
//here is namespace,endpoint,soapaction and methodname
public final static String DISCOVERY_NAMESPACE = "http://schemas.microsoft.com/crm/2007/CrmDiscoveryService/";
public final static String DISCOVERY_ENDPOINT_URL = "https://dev.crm5.dynamics.com/MSCRMServices/2007/Passport/CrmDiscoveryService.asmx";
public final static String SOAPACTION = "http://schemas.microsoft.com/crm/2007/CrmDiscoveryService/Execute";
private String MethodName = "Execute";
//below is the code connectting to crmdiscoveryservice
SoapObject rpc = new SoapObject(DISCOVERY_NAMESPACE, MethodName);
RetrievePolicyRequest retrievePolicyRequest = new RetrievePolicyRequest();
PropertyInfo info = new PropertyInfo();
info.name = "parameters";
info.type = retrievePolicyRequest.getClass();
info.setValue(retrievePolicyRequest);
rpc.addProperty(info);
HttpTransportSE ht = new HttpTransportSE(DISCOVERY_ENDPOINT_URL);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.encodingStyle = "utf-8";
envelope.setOutputSoapObject(rpc);
try {
ht.call(SOAPACTION, envelope);
if (envelope.getResponse() != null) {
SoapPrimitive response = (SoapPrimitive) envelope.bodyIn;
Log.e(tag, response.toString());
}
} catch (IOException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
}
And i defined RetrievePolicyRequest myself. I have tried many times, still have this problem, any people know how to solve this problem?
Thank you!
Here are the following that I think could be going wrong with you code.
You may be using the wrong propertyinfo.name. For example looking at htt(REMOVE THIS)ps://dev.crm5.dynamics.com/MSCRMServices/2007/Passport/CrmDiscoveryService.asmx?WSDL , it sure looks like you want info.name = "Request"; . If this is indeed the case, then your going to have to modify your complex type class to be request as well.
Although you are adding a class as the type of the property with info.type = retrievePolicyRequest.getClass(); this (for some reason I still don't understand) isn't enough. You must also "map" this class to your envelope. Meaning that you should have
envelope.dotNet = "true";
envelope.encodingStyle = "utf-8";
envelope.setOutputSoapObject(rpc);
envelope.addMapping(DISCOVERY_NAMESPACE, "Request", new Request().getClass());
Those are the things I see immediately, here are some things that will deffinately help you (they helped me a ton for soap calls like this).
First, you have to check out soapUI. You can start a 14 day trial. With it, you can point soapUI to a wsdl url, and it will allow you to test the method calls (so you can easily see what your request should look like, and can also see how the returned xml looks). http://www.soapui.org/ . This program will literally spell out what the method is, what the namespace is, what the url is, if it is using soap11 or soap12... etc. USE THIS!!
Second, for complex types like this, you should really see this tutorial: http://seesharpgears.blogspot.com/2010/10/ksoap-android-web-service-tutorial-with.html . I went from bashing my head against the keyboard, to reading this tutorial and having my code work first try (that never happens!).
Good luck, and if you need more help just post! =)
Joey
i am new to android/eclipse(java),in fact this forum too.
Has any one met this situation?
Get input from the user and display the appropriate result by consuming web service from android/eclipse.is there any examples available?
Thank you very much.
I am posting Link of tutorial
Here basic android tutorial to access web service in android basic ksoap android tutorial
and for creating webservice in java use this Tutorial How to create java based web service
Write a web service using java and Then by using ksoap library you will get response. Then Format that response according to your requirement. code for reference:
private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL ="http://localhost/Web_Service.asmx?";// replace it by your Webservice URL
private static final String METHOD_NAME = "Function_Name";
private static final String SOAP_ACTION = "Soap Action";
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("parm_name",prm_value);// Parameter for Method
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try
{
androidHttpTransport.call(SOAP_ACTION, envelope);//call the eb service Method
}
catch (Exception e)
{
e.printStackTrace();
}//Next task is to get Response and format that response
SoapObject response;
response= (SoapObject) envelope.bodyIn;
there are too may example for same Please Google ..................
this is only for initiation
Soap
http://android.vexedlogic.com/2011/04/17/android-lists-iv-accessing-and-consuming-a-soap-web-service-i/
http://seesharpgears.blogspot.in/2010/11/basic-ksoap-android-tutorial.html
Other
http://webhole.net/2011/11/15/android-tutorial-how-to-post-data-from-an-android-app-to-a-website/
http://apachejava.blogspot.in/2011/06/partial-http-post-show-data-webview.html
http://senior.ceng.metu.edu.tr/2009/praeda/2009/01/11/a-simple-restful-client-at-android/
I am trying to get my Android phone to access the IDEOne (www.ideone.com) web service so I can use its APIs for this project I'm working on. the webservice can be accessed using kSoap so I'm using kSoap 2.6.0 which I got from the Google website. My code throws and exception on the following line of code:
httpTransport.call(SOAP_ACTION, envelope); //send request
I checked my wireless connection and used other wireless connection to make sure it was not a firewall problem. I checked the connectionon the Android emulator and there was a connection. I simply ran code others had posted online about connecting Android to web services via kSoap (http://www.helloandroid.com/tutorials/using-ksoap2-android-and-parsing-output-data), with no luck. It throws and exception on the same call function. Any suggestions as to why? Below is my code. Thank you in advance for your help.
public class IDEOneStubI {
private static final String METHOD_NAME = "createSubmission";
private static final String SOAP_ACTION = "http://ideone.com/api/1/service#createSubmission";
private static final String NAMESPACE = "http://ideone.com/api/1/serviceL";
private static final String URL = "http://ideone.com/api/1/service;";
//you can get these values from the wsdl file^
public SoapObject soap(String METHOD_NAME, String SOAP_ACTION, String NAMESPACE, String URL) throws IOException, XmlPullParserException {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); //set up request
request.addProperty("user", "nsbradley"); //variable name, value. I got the variable name, from the wsdl file!
request.addProperty("pass", "12345678");
request.addProperty("sourceCode", "Hello World");
request.addProperty("language", 10);
request.addProperty("input", "");
request.addProperty("run", Boolean.TRUE);
request.addProperty("private", Boolean.FALSE);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); //put all required data into a soap envelope
envelope.dotNet = true;
envelope.setOutputSoapObject(request); //prepare request
HttpTransportSE httpTransport = new HttpTransportSE(URL);
httpTransport.debug = true; //this is optional, use it if you don't want to use a packet sniffer to check what the sent message was
httpTransport.call(SOAP_ACTION, envelope); //send request
SoapObject result=(SoapObject)envelope.getResponse(); //get response
return result;
}
I think your URL string is wrong, remove the semicolon at the end and try again.
Since Android 3.0, you must call this kind of methods from an async task.
First of all make sure that you add permision to internet in your manifest file
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
if that doesnt work try changing
SoapObject result=(SoapObject)envelope.getResponse(); //get response
to
SoapObject result=(SoapObject)envelope.bodyIn; //get response
And also you should put the webservice calls in a try catch block, or throw a SoapFault exception.