解决
我正在尝试解决此错误,但我真的无法弄清楚,原因是我的“transport.call(SOAP_ACTION,信封);” 总是给出错误。我的 Web 服务非常简单,我使用 SoupUI 对其进行了测试,我使用 nusoap 在 php 中构建了它。希望有人可以提供帮助。在此先感谢您。
错误描述:Open Declaration void org.ksoap2.transport.HttpTransportSE.call(String soapAction, SoapEnvelope envelope) throws IOException, XmlPullParserException
解析度; 为了修复我的“transport.call(SOAP_ACTION,envelope)”错误,我必须做两件事,1º我使用了这行代码 System.setProperty("http.keepAlive", "false");,因为看起来是 api < 9 的 ksoap2 的问题,之后我只是在 android manifest 上添加了互联网的权限,它就起作用了。
这是我的安卓代码
//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";
//连接到网络服务器
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>