Ksoap webservices返回false而不是string

时间:2012-03-12 13:42:08

标签: java android web-services ksoap2

我无法理解为什么Ksoap没有返回字符串而只返回false,这是webservice的代码:

 private static final String SOAP_ACTION = "";
private static final String METHOD_NAME = "serverImpService";
private static final String NAMESPACE = "http://server/";
private static final String URL = "http://localhost:9841/server/";
TextView tv;
String results = "";

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    tv = (TextView)findViewById(R.id.TextView01);

    SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);

    SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
    soapEnvelope.dotNet = true;
    soapEnvelope.setOutputSoapObject(Request);

    HttpTransportSE aht = new HttpTransportSE(URL); 
    try {
        aht.call(SOAP_ACTION, soapEnvelope);
        SoapPrimitive resultsString = (SoapPrimitive)soapEnvelope.getResponse();
        results = resultsString.toString();
        tv.setText("Message : " + results);     
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }

这是WDSL文件:

<types></types>
<message name="getMessage"></message>
<message name="getMessageResponse">
<part name="return" type="xsd:string"></part>
</message>
<portType name="webServer">
<operation name="getMessage">
<input message="tns:getMessage"></input>
<output message="tns:getMessageResponse"></output>
</operation>
</portType>
<binding name="serverImpPortBinding" type="tns:webServer">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc"></soap:binding>
<operation name="getMessage">
<soap:operation soapAction=""></soap:operation>
<input>

<soap:body use="literal" namespace="http://server/"></soap:body>
</input>
<output>
<soap:body use="literal" namespace="http://server/"></soap:body>
</output>
</operation>
</binding>
<service name="serverImpService">
<port name="serverImpPort" binding="tns:serverImpPortBinding">
<soap:address location="http://localhost:9841/server"></soap:address>
</port>
</service>
</definitions>

所有服务器都会返回消息

public class serverImp implements webServer {

    public String getMessage(){
    message = "test";
    return message;
}

android的结果是:“false”,我尝试过编辑SOAP_ACTION,METHOD_NAME等没有运气,

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

试试这个:

Object response = envelope.getResponse();
String result = response.toString();