2012-08-22 114 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“

相关问题