2014-07-18 68 views
0

我是新來的android開發,我使用Ksoap2來訪問.net Web服務和調用執行沒有參數或整數參數很好但是與字符串參數我什麼都沒有。下面的代碼的目的是在餐館中按名稱搜索並返回它們的列表。ksoap2請求與字符串參數返回null

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> 

任何人可以幫助我嗎?

回答

0

您需要在調用httptransport後添加一行並返回最終結果。 檢查此解決方案它將工作

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