带String参数的ksoap2请求返回null

时间:2014-07-18 20:39:12

标签: java android ksoap2

我是android开发的新手,我使用Ksoap2来访问.Net web服务并且调用执行得很好而没有参数或整数参数但是使用String参数我什么都没得到。下面代码的目的是按名称在餐馆中搜索并返回它们的列表。

    Action = "SearchResturant";
    request = new SoapObject(WSDL_TARGET_NAMESPACE, Action);

    PropertyInfo pi = new PropertyInfo();
    pi.setName("name");
     pi.setValue(Name);
    pi.setType(String.class);

    request.addProperty(pi);
   SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
        SoapEnvelope.VER11);
       //   envelope.dotNet = true;
       // envelope.bodyOut = request;

        envelope.setOutputSoapObject(request);

        envelope.setAddAdornments(false);
        envelope.implicitTypes = true;

        HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
        httpTransport.debug=true;
        httpTransport.setXmlVersionTag("<?xml version=\"1.0\" encoding= \"UTF-8\"?>");

        try
        {
        httpTransport.call(SOAP_ACTION + Action, envelope);

        return httpTransport.responseDump.toString();
        }
        catch (Exception exception)
        {

        isEroor=true;
        return exception.toString();

        }

这是我得到的回应:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><SearchResturantResponse xmlns="http://RST.org/"><SearchResturantResult /></SearchResturantResponse></soap:Body></soap:Envelope>

有人能帮帮我吗?

1 个答案:

答案 0 :(得分:0)

您需要在调用httptransport后添加一行并返回最终结果。 检查这个解决方案是否可行

         httpTransport.call(SOAP_ACTION + Action, envelope);
         SoapObject final_result=(SoapObject)envelope.bodyIn;
         return final_result.toString();