I need to invoke a web service from android app. I have the wsdl file of a web service created in java, i don't have the source code of the same. In java, i use the "Generate Client" option to generate the files from a wsdl and then invoke the web service via my java app using Axis.jar. When i click the "Generate Client" option the files are generated along with some compilation errors. But the same thing when i am doing in an java app, the generated files does not have any compilation errors. Please inform the proper way of doing the same from the android prospective. Regads,
Asked
Active
Viewed 3,055 times
0
-
See [this](http://stackoverflow.com/questions/297586/how-to-call-soap-web-service-with-android) question on SO. – Jeshurun Jun 02 '12 at 04:33
1 Answers
0
In android you can use ksoap library and call the required webservice. Include ksoap library using build path and use the following code to invoke the webservice. find the ksoap library in this path Ksoap library path
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.MarshalBase64;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.app.Activity;
import android.os.Bundle;
public class SVCWebServiceActivity extends Activity {
/** Called when the activity is first created. */
private static final String SOAP_ACTION = "http://tempuri.org/GetByteArray";
private static final String METHOD_NAME = "GetByteArray";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL = "http://IPAddress/Serviceforc/Service.asmx";
private String byteStr = "srikar";
private byte[] bytedata = byteStr.getBytes();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
System.out.println("bytedata is "+bytedata[0]);
HttpTransportSE httpTransport = null;
MarshalBase64 marshal = null;
SoapObject request = null;
request = new SoapObject(NAMESPACE, METHOD_NAME);
PropertyInfo pi = new PropertyInfo();
pi.setName("value");
pi.setValue(bytedata);
pi.setType(MarshalBase64.BYTE_ARRAY_CLASS);
request.addProperty(pi);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
marshal = new MarshalBase64();
marshal.register(envelope);
envelope.setOutputSoapObject(request);
httpTransport = new HttpTransportSE(URL);
Object response;
try {
httpTransport.call(SOAP_ACTION, envelope);
response = envelope.getResponse();
} catch (Exception exception) {
exception.printStackTrace();
System.out.println("Exception is " + exception.toString());
// strRes = exception.toString();
response = exception.toString();
}
System.out.println("Response is "+response.toString());
}
}

user1203673
- 1,015
- 7
- 15