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>
感谢您的建议!
---
请求转储
<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>
响应转储
<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>
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"
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>
---
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
终于我修好了!!!!
问题发生是因为......
但是,我使用“GAE”而不是“.NET”,所以上面的代码应该更改为
Finally, I fixed it!!!!
The problem happend because...
However, I use "GAE" not ".NET", so the above code should change to