KSOAP2-Android addPropery doesn't work
I made a WS on the GAE. (http://testitthanks.appspot.com/)
And I want to use KSOAP2 on Android to get response.
Here is my code:
public class HelloSOAPAndroidClientActivity extends Activity {
//you can get these values from the wsdl file
private static final String SOAP_ACTION = "";
private static final String OPERATION_NAME = "sayHello";
private static final String WSDL_TARGET_NAMESPACE = "http://example.com/";
private static final String SOAP_ADDRESS = "http://testitthanks.appspot.com/hellosoapserver";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView textView = new TextView(this);
setContentView(textView);
SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,
OPERATION_NAME);
request.addProperty("arg0","ONE");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
httpTransport.debug = true;
try {
httpTransport.call(SOAP_ACTION, envelope);
Log.v("TEST", httpTransport.requestDump);
Log.v("TEST", httpTransport.responseDump);
Object response = envelope.getResponse();
textView.setText(response.toString());
} catch (Exception exception) {
textView.setText(exception.toString());
}
}
}
It should show
Hello, ONE!
But sadly it always looks like
Hello, null!
Here is my WSDL:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.6 in JDK 6. -->
<definitions targetNamespace="http://example.com/" name="GreeterService" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://example.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
<types>
<xsd:schema>
<xsd:import namespace="http://example.com/" schemaLocation="GreeterService_schema1.xsd"/>
</xsd:schema>
</types>
<message name="sayHello">
<part name="parameters" element="tns:sayHello"/>
</message>
<message name="sayHelloResponse">
<part name="parameters" element="tns:sayHelloResponse"/>
</message>
<message name="sayGoodbye">
<part name="parameters" element="tns:sayGoodbye"/>
</message>
<message name="sayGoodbyeResponse">
<part name="parameters" element="tns:sayGoodbyeResponse"/>
</message>
<portType name="Greeter">
<operation name="sayHello">
<input message="tns:sayHello"/>
<output message="tns:sayHelloResponse"/>
</operation>
<operation name="sayGoodbye">
<input message="tns:sayGoodbye"/>
<output message="tns:sayGoodbyeResponse"/>
</operation>
</portType>
<binding name="GreeterPortBinding" type="tns:Greeter">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="sayHello">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="sayGoodbye">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="GreeterService">
<port name="GreeterPort" binding="tns:GreeterPortBinding">
<soap:address location="http://testitthanks.appspot.com/hellosoapserver"/>
</port>
</service>
</definitions>
Thanks for any advice!
---
requestDump
<v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance"
xmlns:d="http://www.w3.org/2001/XMLSchema"
xmln开发者_如何学Gos:c="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:v="http://schemas.xmlsoap.org/soap/envelope/">
<v:Header />
<v:Body>
<sayHello xmlns="http://example.com/" id="o0" c:root="1">
<arg0 i:type="d:string">ONE</arg0>
</sayHello>
</v:Body>
</v:Envelope>
responseDump
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<ns3:sayHelloResponse xmlns:ns3="http://example.com/">
<return>Hello, null!</return>
</ns3:sayHelloResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
---
My xsd
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema version="1.0" targetNamespace="http://example.com/" xmlns:tns="http://example.com/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="sayGoodbye" type="tns:sayGoodbye"/>
<xs:element name="sayGoodbyeResponse" type="tns:sayGoodbyeResponse"/>
<xs:element name="sayHello" type="tns:sayHello"/>
<xs:element name="sayHelloResponse" type="tns:sayHelloResponse"/>
<xs:complexType name="sayHello">
<xs:sequence>
<xs:element name="arg0" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="sayHelloResponse">
<xs:sequence>
<xs:element name="return" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="sayGoodbye">
<xs:sequence>
<xs:element name="arg0" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="sayGoodbyeResponse">
<xs:sequence>
<xs:element name="return" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
Finally, I fixed it!!!!
The problem happend because...
envelope.dotNet = true;
However, I use "GAE" not ".NET", so the above code should change to
envelope.dotNet = false;
精彩评论