开发者

Android: soap primitive error

I am having some issues with accessing a web service. Getting ClassCastException Error. Consider a scenario that I am trying to access a method of a web-service and the webservice is supposed to return two strings (Lets say String1 and String2). Moreover, I have to provide or pass two parameters (lets say Parameter 1 and Parameter 2 where Parameter 1 should be integer and Parameter 2 should be String) Here is my code

public class MyWebService extends Activity {

private static final String SOAP_ACTION ="http://www.mywebsite.com/myMethod";
private static final String METHOD_NAME = "MyMethod";
private static final String NAMESPACE = "http://www.myNamespace/";
    private static final String URL = "http://mysession.com/myservice.asmx?WSDL";


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    try {
        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

        PropertyInfo pi = new PropertyInfo(); 开发者_如何学JAVA  
        pi.setName("Parameter 1");
        pi.setValue(1);
        pi.setType(pi.INTEGER_CLASS);
        request.addProperty(pi);

        PropertyInfo pi2 = new PropertyInfo();  
        pi2.setName("Parameter 2");
        pi2.setValue("Any string");
        pi2.setType(pi2.STRING_CLASS);
        request.addProperty(pi2);

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

        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
        androidHttpTransport.call(SOAP_ACTION, envelope);                   
        SoapObject result=(SoapObject)envelope.getResponse();               


        String string1=result.getProperty(0).toString();
        String string2=result.getProperty(1).toString();


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

    }        
}

}

This is the exception I am getting java.lang.ClassCastException: org.ksoap2.serialization.SoapPrimitive

Can anyone tell me if I am doing something wrong here.. Thanks


Try this,

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

OR

Object result= (Object)envelope.getResponse();

instead of

SoapObject result=(SoapObject)envelope.getResponse();


Try this:

SoapObject request = new SoapObject(SOAP_NAMESPACE,SOAP_METHOD);
request.addProperty("name", abcd);
request.addProperty("age", 30);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜