我正在尝试使用下面的 java 代码访问 SOAP 服务,我想在我的 Android 应用程序中使用该代码,但得到XmlPullParserException
.
org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope (position:START_TAG <{http://www.w3.org/2003/05/soap-envelope}SOAP-ENV:Envelope>@1:114 in java.io.InputStreamReader@4a65e0)
我检查了所有与 XmlPullParserException 相关的标签,没有运气。请帮我纠正我的代码。
import java.io.IOException;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.SoapFault;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;
public class SoapClientClass {
private static String SOAP_ACTION = "/Process Definition";
private static String METHOD_NAME = "EmployeeDetailsOperation";
private static String NAMESPACE = "http://InputMessageNamespace";
private static String URL ="http://10.213.45.05:5026/EmployeeService";
public static void main(String[] args)
{
webserviceCall();
}
private static void webserviceCall() {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
// Pass parameters as Key value pair to URL
request.addProperty("EmployeeId", "121");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
} catch (IOException e) {
System.out.println("IOException");
e.printStackTrace();
} catch (XmlPullParserException e) {
System.out.println("XmlPullParserException");
e.printStackTrace();
}
SoapPrimitive result = null;
try {
result = (SoapPrimitive)envelope.getResponse();
} catch (SoapFault e) {
System.out.println("SoapFault");
e.printStackTrace();
}
//to get the data
String resultData = result.toString();
System.out.println("Result as String: \n"+resultData);
}
}