解决
我正在尝试解决此错误,但我真的无法解决这个问题,原因是我的“transport.call(SOAP_ACTION,envelope);”总是给出错误。我的Web服务非常简单,我用SoupUI测试它,我使用nusoap在php中构建它。希望有人能提供帮助。谢谢你。
错误说明:打开声明void org.ksoap2.transport.HttpTransportSE.call(String soapAction,SoapEnvelope envelope)抛出IOException,XmlPullParserException
分辨率;为了修复我的“transport.call(SOAP_ACTION,envelope)” 错误,我不得不做两件事,1º我使用了这行代码 System.setProperty(“http.keepAlive”,“false”);,因为出现了 是api的ksoap2的问题< 9,之后我才加入了 对于互联网的Android清单的许可,它有效。
这是我的安卓代码
//SOUP web service
private static final String SOAP_ACTION = "urn:primeFactorization#doCalc";
private static final String METHOD_NAME = "doCalc";
private static final String NAMESPACE = "urn:primeFactorization";
private static final String URL = "http://192.168.1.33/androidWebService/calcNumber.php";
//连接到webServer
public SoapObject getPrimeFactorization(String number) throws Exception{
System.setProperty("http.keepAlive", "false");//--> This resolved my problem
SoapObject request = new SoapObject(NAMESPACE,METHOD_NAME);
request.addProperty("number",number);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
//envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE transport = new HttpTransportSE(URL);
try{
transport.call(SOAP_ACTION, envelope); //This is were i get the error:S<----
Log.v("TEST","runs ok attributes "+envelope.getResponse().toString());
}catch (Exception e) {
e.printStackTrace();
}
return (SoapObject) envelope.getResponse();
}
//和我的Web服务WSDL
<definitions xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="urn:primeFactorization" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="urn:primeFactorization">
<types>
<xsd:schema targetNamespace="urn:primeFactorization">
<xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
<xsd:import namespace="http://schemas.xmlsoap.org/wsdl/"/>
</xsd:schema>
</types>
<message name="doCalcRequest">
<part name="number" type="xsd:string"/>
</message>
<message name="doCalcResponse">
<part name="return" type="xsd:string"/>
</message>
<portType name="primeFactorizationPortType">
<operation name="doCalc">
<documentation>Calculates the prime factorial of a given number</documentation>
<input message="tns:doCalcRequest"/>
<output message="tns:doCalcResponse"/>
</operation>
</portType>
<binding name="primeFactorizationBinding" type="tns:primeFactorizationPortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="doCalc">
<soap:operation soapAction="urn:primeFactorization#doCalc" style="rpc"/>
<input>
<soap:body use="encoded" namespace="urn:primeFactorization" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body use="encoded" namespace="urn:primeFactorization" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
</binding>
<service name="primeFactorization">
<port name="primeFactorizationPort" binding="tns:primeFactorizationBinding">
<soap:address location="http://192.168.1.33/androidWebService/calcNumber.php"/>
</port>
</service>
答案 0 :(得分:1)
使用它来获取您的请求结果:
SoapObject result = (SoapObject)envelope.bodyIn;
Log.v("TEST","runs ok attributes "+result.getProperty(0).toString());
答案 1 :(得分:1)
为了修复我的“transport.call(SOAP_ACTION,envelope)”错误,我不得不做两件事,1º我使用了这行代码System.setProperty(“http.keepAlive”,“false”);,因为看起来这是一个问题的ksoap2 for android api&lt; 9,之后我刚刚在互联网的Android清单上添加了权限,并且有效。