我正在尝试使用以下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);
}
}
答案 0 :(得分:1)
我遇到了同样的问题,它与SoapEnvelope版本有关。
在这行代码中,当我将其更改为VER11(您已使用它)时,我使用的是VER12
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
也许你可以测试其他版本有三个从VER10到VER12
答案 1 :(得分:0)
根据以下代码行编辑你的代码...
private static String SOAP_ACTION = "http://InputMessageNamespace/Process Definition";
private static String METHOD_NAME = "EmployeeDetailsOperation";
private static String NAMESPACE = "http://InputMessageNamespace";
答案 2 :(得分:0)
尝试在网址字符串的末尾添加“/”:
private static String URL ="http://10.213.45.05:5026/EmployeeService/";
而不是SOAP_ACTION使用NAMESPACE + METHOD_NAME
答案 3 :(得分:0)
我遇到了类似的问题,我想这个问题是因为我们用来连接网站的URL。所以我通过更改我的网站网址http://www.example.com/index.php/api/v2_soap/?wsdl/来解决了这个问题。
示例:
HttpTransportSE androidHttpTransport = new HttpTransportSE(http://www.example.com.com/index.php/api/v2_soap/?wsdl/,900000000); androidHttpTransport.call(“”,env);