经过一整天的寻找,我仍然找不到解决问题的办法。
我有一个WebService,它给了我下面的WSDL文件,我上传到pastebin,因为它真的很大。
首先,我想实现ping函数,您可以用字符串值调用这个函数,并将字符串值返回给客户端。我认为有关的部分是:
<wsdl:operation name="ping">
<wsdl:input message="tns:ping" name="ping"></wsdl:input>
<wsdl:output message="tns:pingResponse" name="pingResponse"></wsdl:output>
<wsdl:fault message="tns:ServerException" name="ServerException"></wsdl:fault>
<wsdl:fault message="tns:UserException" name="UserException"></wsdl:fault>
</wsdl:operation>以及:
<xs:complexType name="ping">
<xs:sequence>
<xs:element minOccurs="0" name="in" type="xs:string"/>
</xs:sequence>
</xs:complexType>无论如何,如果您能够查看实际的wsdl文件并告诉我这些文件是否真的是其中的相关部分,那就太好了。
所以,要用安卓来访问这个系统,我要使用ksoap2。我的守则如下:
SoapObject request = new SoapObject("http://shared.bimserver.org/", "ping");
request.addProperty("in", "Hallo Welt");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE httpTransport = new HttpTransportSE("http://10.0.0.5:8082/soap");
httpTransport.debug = true;
httpTransport.call("http://shared.bimserver.org/ping", envelope);这将创建以下请求:
<v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/"><v:Header /><v:Body><ping xmlns="http://shared.bimserver.org/" id="o0" c:root="1"><in i:type="d:string">Hallo Welt</in></ping></v:Body></v:Envelope>但我得到了这样的回应:
<soap:Body><soap:Fault><faultcode>soap:Client</faultcode><faultstring>Unmarshalling Error: unexpected element (uri:"http://shared.bimserver.org/", local:"in"). Expected elements are <{}in> </faultstring></soap:Fault></soap:Body>因此,我希望参数"in“不能有名称空间。我尝试了不同的方法,比如:
PropertyInfo info = new PropertyInfo();
info.setName("in");
info.setNamespace("");
info.setValue("Hallo Welt");
request.addProperty(info);但这并没有改变请求或回应。
我还从soap对象中删除了名称空间:
SoapObject request = new SoapObject("", "ping");以下是我的要求:
<v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/"><v:Header /><v:Body><ping xmlns="" id="o0" c:root="1"><in i:type="d:string">Hallo Welt</in></ping></v:Body></v:Envelope>以及以下答复:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><soap:Fault><faultcode>soap:Client</faultcode><faultstring>Unexpected wrapper element ping found. Expected {http://shared.bimserver.org/}ping.</faultstring></soap:Fault></soap:Body></soap:Envelope>因此,在这里,参数"in“必须没有名称空间,但是ping请求必须有一个命名空间。
请帮帮我。我试过任何我能想象得到的东西。
编辑:和soapUI --我发现,响应应该是这样的:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:shar="http://shared.bimserver.org/">
<soapenv:Header/>
<soapenv:Body>
<shar:ping>
<!--Optional:-->
<in>Hallo</in>
</shar:ping>
</soapenv:Body>
</soapenv:Envelope>我的请求如下:
<v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/"><v:Header />
<v:Body>
<ping xmlns="http://shared.bimserver.org/">
<in i:type="d:string">test</in>
</ping>
</v:Body>
</v:Envelope>如何使我的请求看起来像所需的请求?
发布于 2013-03-14 13:15:55
添加属性的命名空间:
PropertyInfo info = new PropertyInfo();
info.setNamespace("http://www.w3.org/2001/XMLSchema-instance");
info.setName("in");
info.setValue("Hallo Welt");
info.setType(PropertyInfo.STRING_CLASS);
request.addProperty(info);https://stackoverflow.com/questions/15384028
复制相似问题