我尝试从网络服务调用网络方法“注册”。它包含一个输入参数和一个输出。
HttpTransportSE httpTransport=null;
try
{
String organization = "Слоник Зеленый";
String method = "Registration";
SoapObject request = new SoapObject("http://www.ServiceDesk.org", method);
PropertyInfo pi1 = new PropertyInfo();
pi1.setName("Organisation");
pi1.setValue(organization);
pi1.setType(String.class);
request.addProperty(pi1);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); //VER.10,VER.11,VER.12 don't help
envelope.setOutputSoapObject(request);
// envelope.implicitTypes = true; #don't help me
envelope.dotNet = false; # "true" value don't help
List<HeaderProperty> headerList = new ArrayList<HeaderProperty>();
headerList.add(new HeaderProperty("Authorization", "Basic " + org.kobjects.base64.Base64.encode("user:password".getBytes())));
httpTransport = new HttpTransportSE(MainAsync.wsdlSchema);
httpTransport.debug=true;
httpTransport.call("http://www.ServiceDesk.org#ServiceDesk:Registration", envelope,headerList);
SoapObject result =(SoapObject) envelope.bodyIn;
String roleId = result.getProperty("return").toString();
httpTransport.reset();
return roleId;
} catch (Exception e) {
Log.e(httpTransport.responseDump);
Log.e("Request "+httpTransport.requestDump);
e.printStackTrace();
if(httpTransport!=null)
httpTransport.reset();
return"";
} finally{
if(httpTransport!=null)
httpTransport.reset();
}
但是,请接受下一个错误:
org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope (position:START_TAG <definitions name='ServiceDesk' targetNamespace='http://www.ServiceDesk.org'>@9:48 in java.io.InputStreamReader@76ed5528)
at org.kxml2.io.KXmlParser.exception(KXmlParser.java:242)
at org.kxml2.io.KXmlParser.require(KXmlParser.java:1384)
at org.ksoap2.SoapEnvelope.parse(SoapEnvelope.java:128)
at org.ksoap2.transport.Transport.parseResponse(Transport.java:118)
at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:275)
at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:118)
这是我的wsdl文件:
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap12bind="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:soapbind="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://www.ServiceDesk.org" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsd1="http://www.ServiceDesk.org" name="ServiceDesk" targetNamespace="http://www.ServiceDesk.org">
<types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xs1="http://www.ServiceDesk.org" targetNamespace="http://www.ServiceDesk.org" elementFormDefault="qualified">
<xs:element name="Registration">
<xs:complexType>
<xs:sequence>
<xs:element name="Organisation" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</types>
<message name="RegistrationRequestMessage">
<part name="parameters" element="tns:Registration"/>
</message>
<message name="RegistrationResponseMessage">
<part name="parameters" element="tns:RegistrationResponse"/>
</message>
<portType name="ServiceDeskPortType">
<operation name="Registration">
<input message="tns:RegistrationRequestMessage"/>
<output message="tns:RegistrationResponseMessage"/>
</operation>
<binding name="ServiceDeskSoapBinding" type="tns:ServiceDeskPortType">
<soapbind:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="Registration">
<soapbind:operation style="document" soapAction="http://www.ServiceDesk.org#ServiceDesk:Registration"/>
<input>
<soapbind:body use="literal"/>
</input>
<output>
<soapbind:body use="literal"/>
</output>
</operation>
</binding-name>
<service name="ServiceDesk">
<port name="ServiceDeskSoap" binding="tns:ServiceDeskSoapBinding">
<documentation>
<wsi:Claim xmlns:wsi="http://ws-i.org/schemas/conformanceClaim/" conformsTo="http://ws-i.org/profiles/basic/1.1"/>
</documentation>
<soapbind:address location="http://volga.rarus.ru/abc2009_artur/ru/ws/ServiceDesk"/>
</port>
<port name="ServiceDeskSoap12" binding="tns:ServiceDeskSoap12Binding">
<soap12bind:address location="http://volga.rarus.ru/abc2009_artur/ru/ws/ServiceDesk"/>
</port>
</service>
我在类似问题上解析stackoverflow,但它对我没有帮助。
答案 0 :(得分:1)
我试过这个并且对我来说是正确的:
好吧,我认为NAMESPACE字符串应该是SoapObject构造函数中的第一个参数。 call()方法也是一样的(这里应该是NAMESPACE + METHOD_NAME作为第一个参数)
试试这个:
_envelope.setOutputSoapObject(_client);
而不是:
_envelope.bodyOut = _client;
要获得响应:它取决于您的Web服务返回的内容(原始对象还是复杂对象?)
来自this link的答案: