我正在尝试使用ksoap2从android调用webmethod。我使用soapobject方法addProperty设置webmethod的参数但不能在webmethod中设置参数。 我创建了一个AsyncTask类,并且它的doInBackgroud()方法覆盖并从中调用webmethod。
cannot set webmethod parameters
以下是代码:
package com.example.locumapllication;
import android.os.AsyncTask;
public class MyAsyncTask extends AsyncTask<String, Void, Object> {
private String METHOD_NAME="";
private String NAMESPACE="http://ws.easyway3e.com/";
private String SOAP_ACTION="";
private static final String URL="http://192.168.2.155:8080/WebService/DBConn?wsdl";
@Override
protected Object doInBackground(String... params) {
System.out.println("Call-1"+params[0]+params[1]+params[2]+params[3]);
METHOD_NAME="openConnection";
SoapObject request=new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("arg0",params[0]);
request.addProperty("arg1",params[1]);
request.addProperty("arg2",params[2]);
request.addProperty("arg3",params[3]);
System.out.println("Property Set ="+request.getPropertyCount());
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;
envelope.setOutputSoapObject(request);
System.out.println(envelope.bodyOut.toString());
HttpTransportSE androidHttpTranportSE=new HttpTransportSE(URL);
try {
SOAP_ACTION= METHOD_NAME + NAMESPACE;
androidHttpTranportSE.call(SOAP_ACTION, envelope);
SoapPrimitive resultsRequestSOAP = (SoapPrimitive) envelope.getResponse();
System.out.println(" Connection is =>"+resultsRequestSOAP.toString());
} catch (IOException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
}
Object result = null;
try {
result = envelope.getResponse();
} catch (SoapFault e) {
e.printStackTrace();
}
return result;
}
}
我可以使用soapobject的setproperty方法来设置webmethod的属性但是它不能设置webmethod的参数。
我使用jaxws创建了webservices,所以我想知道与ksoap2和jaxws集成是否有任何问题。还指导我解决这个问题。
答案 0 :(得分:0)
看看属性是如何设置的,我希望这可能会有所帮助
SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
//parameters added here..
PropertyInfo pi = new PropertyInfo();
pi.setName("EmailAddress");
pi.setValue("dilip.mariya@gmail.com");
pi.setType(String.class);
Request.addProperty(pi);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(Request);
AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL);
Log.e("above try","");
try
{
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject response = (SoapObject)envelope.bodyIn;
String result = (response.getProperty(0).toString());
// String gfdgf = (response.getProperty(1).toString());
Log.e("", result);
}
catch(Exception e)
{
e.printStackTrace();
}
答案 1 :(得分:0)
尝试更改您的网址(如果您使用的是虚拟设备):
网址=“http://10.0.2.2:8080/WebService/DBConn?wsdl”