安卓系统-无法让ksoap2与我的nusoup网络服务配合使用



已解决

我正在尝试解决这个错误,但我真的搞不清楚,原因是我的"transport.call(SOAP_ACTION,envelope);"总是出错。我的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,然后我添加了允许在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>

使用它来获得请求的结果:

SoapObject result = (SoapObject)envelope.bodyIn;
Log.v("TEST","runs ok attributes "+result.getProperty(0).toString());

为了修复我的"transport.call(SOAP_ACTION,envelope)"错误,我必须做两件事,1º我使用了这行代码System.setProperty("http.keepAlive","false");,因为这似乎是安卓api的ksoap2的一个问题<9,在那之后,我刚刚添加了互联网安卓清单上的权限,它就工作了。

最新更新