2011-08-08 76 views
0
Am new to android I made soap request with the help of Ksoap2,I manage to request and get responce without any parameters ,But when I pass the parameters it doesnt responce me. 
Android code: 
    private static final String METHOD_NAME ="HelloWorld"; 
    private static final String SOAP_ACTION ="http://tempuri.org/HelloWorld"; 
    private static final String NAMESPACE ="http://tempuri.org"; 
    private static final String URL ="http://10.0.2.2:64580/Service1.asmx"; 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); //set up request 
     // SoapObject parameters = new SoapObject(NAMESPACE, METHOD_NAME); 

     request.addProperty("s1","A"); 
      SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); //put all required data into a soap envelope 
     envelope.setOutputSoapObject(request); //prepare request 
     AndroidHttpTransport httpTransport = new AndroidHttpTransport(URL); 
     httpTransport.debug = true; //this is optional, use it if you don't want to use a packet sniffer to check what the sent 
            //message was (httpTransport.requestDump) 
     try { 

     httpTransport.call(SOAP_ACTION, envelope); 
     System.out.println("hhishihihii"); 
     SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyOut; 
     SoapObject response = (SoapObject)envelope.bodyIn; 
     System.out.println("result"+response); 
     } catch (IOException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } catch (XmlPullParserException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } //send request 
     //SoapObject result = (SoapObject) envelope.getResponse(); 
     //SoapObject response = (SoapObject)envelope.bodyIn; 
    //SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyOut; 

        } 
} 
    WEBSERVICE CODE: 
namespace WebService1 
{ 
    /// <summary> 
    /// Summary description for Service1 
    /// </summary> 
    [WebService(Namespace = "http://tempuri.org/")] 
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] 
    [ToolboxItem(false)] 
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService] 
    public class Service1 : System.Web.Services.WebService 
    { 

     [WebMethod] 
     public string HelloWorld(String s1) 
     { 
      return s1; 
     } 
    } 
} 

回答

0

在我的部分中,我使用了soap原語,因爲我的service方法返回原始類型。

在你一個,request.addProperty("s1","A");你的方法參數名稱爲「S1」

仔細檢查你的參數名稱&試試這個代碼;

// ksoap2 calling wcf 
public SoapPrimitive soapPrimitive(String METHOD_NAME, String SOAP_ACTION,String NAMESPACE, String URL) throws IOException, XmlPullParserException { 
    SoapPrimitive responses = null; 
    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); // set up 
    request.addProperty("strExec", strExecutive); 
    request.addProperty("strBusinessUnit", strBusinessUnit); 
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); // put all required data into a soap 
    envelope.dotNet = true; 
    envelope.setOutputSoapObject(request); 
    AndroidHttpTransport httpTransport = new AndroidHttpTransport(URL); 
    httpTransport.debug = true; 

    try { 
     httpTransport.call(SOAP_ACTION, envelope); 
     responses = (SoapPrimitive) envelope.getResponse(); 

     }catch(SocketException ex){ 
      ex.printStackTrace(); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 

    return responses; 
}