2012-08-22 165 views
0

我想從android使用kso​​ap2調用webmethod。我使用soapobject方法addProperty設置webmethod的參數,但不能在webmethod中設置參數。 我創建了一個AsyncTask類和它的doInBackgroud()方法,並從中調用webmethod。從android使用kso​​ap2調用webmethod

cannot set webmethod parameters 

以下是代碼:

package com.example.locumapllication; 

import android.os.AsyncTask; 

public class MyAsyncTask extends AsyncTask<String, Void, Object> { 

private String METHOD_NAME=""; 
private String NAMESPACE="http://ws.easyway3e.com/"; 
private String SOAP_ACTION=""; 
private static final String URL="http://192.168.2.155:8080/WebService/DBConn?wsdl"; 

@Override 
protected Object doInBackground(String... params) { 

    System.out.println("Call-1"+params[0]+params[1]+params[2]+params[3]); 
    METHOD_NAME="openConnection";    
    SoapObject request=new SoapObject(NAMESPACE, METHOD_NAME); 



    request.addProperty("arg0",params[0]); 
    request.addProperty("arg1",params[1]); 
    request.addProperty("arg2",params[2]); 
    request.addProperty("arg3",params[3]); 
    System.out.println("Property Set ="+request.getPropertyCount()); 

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 

    envelope.dotNet=true; 
    envelope.setOutputSoapObject(request); 


    System.out.println(envelope.bodyOut.toString()); 

    HttpTransportSE androidHttpTranportSE=new HttpTransportSE(URL); 


     try { 
      SOAP_ACTION= METHOD_NAME + NAMESPACE; 

      androidHttpTranportSE.call(SOAP_ACTION, envelope); 

      SoapPrimitive resultsRequestSOAP = (SoapPrimitive) envelope.getResponse(); 

       System.out.println(" Connection is =>"+resultsRequestSOAP.toString()); 

     } catch (IOException e) { 

      e.printStackTrace(); 
     } catch (XmlPullParserException e) { 

      e.printStackTrace(); 
     } 
     Object result = null; 
     try { 
      result = envelope.getResponse(); 
     } catch (SoapFault e) { 

      e.printStackTrace(); 
     } 

    return result; 
} 

}

我可以做soapobject的setProperty方法來設置的webmethod財產,但不能設置的WebMethod的參數。

我已經使用jaxws創建了webservices,所以我想知道是否有任何問題要與ksoap2和jaxws集成。也指導我解決這個問題。

回答

0

看proprty是如何設置在這裏我希望這可以幫助

SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME); 
    //parameters added here.. 
    PropertyInfo pi = new PropertyInfo(); 
    pi.setName("EmailAddress"); 
    pi.setValue("[email protected]"); 
    pi.setType(String.class); 
    Request.addProperty(pi); 

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
    envelope.dotNet = true; 
    envelope.setOutputSoapObject(Request); 

    AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL); 
    Log.e("above try",""); 
    try 
    { 
     androidHttpTransport.call(SOAP_ACTION, envelope); 
     SoapObject response = (SoapObject)envelope.bodyIn; 

     String result = (response.getProperty(0).toString()); 
     // String gfdgf = (response.getProperty(1).toString()); 
     Log.e("", result); 
    } 
    catch(Exception e) 
    { 
     e.printStackTrace(); 
    } 
+0

我可以做到,但參數沒有設置爲webmethod – user1508234

0

試圖改變自己的網址(如果您使用的是虛擬設備):

URL =「HTTP://10.0 .2.2:8080/WebService/DBConn?wsdl「

相關問題