KSOAP2-Android addPropery不起作用
|
我在GAE上创建了WS。 (http://testitthanks.appspot.com/)
我想在Android上使用KSOAP2以获得响应。
这是我的代码:
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());
}
}
}
它应该显示
你好,一个!
但是可悲的是,它总是看起来像
您好,空!
这是我的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>
感谢您的任何建议!
---
requestDump
<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>
<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>
---
我的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>
没有找到相关结果
已邀请:
1 个回复
稀瓣囊
但是,我使用的是\“ GAE \”而不是\“。NET \”,因此上述代码应更改为