简体   繁体   中英

web service client for android

I have written a simple webservice in eclipse using this tutorial http://www.ibm.com/developerworks/webservices/tutorials/ws-eclipse-javase1/ws-eclipse-javase1-pdf.pdf . Now I have to write the client for this web service. This is my code:

public class MainActivity extends Activity {
/** Called when the activity is first created. */
private static final String SOAP_ACTION = "http://wsServer.myfirst.com/getGreeting";
private static final String METHOD_NAME = "getGreeting";
private static final String NAMESPACE = "http://wsServer.myfirst.com/";
private static final String URL = "http://10.0.2.2:8080/wsServerExample?wsdl";

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    try {
        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
        request.addProperty("arg0","Nicola");            

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

        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);           

        androidHttpTransport.call(SOAP_ACTION, envelope);
        SoapObject response = (SoapObject)envelope.getResponse();
        String r =  (response.getProperty(0).toString());           
    }
    catch (Exception e) {
        System.out.println(e.getMessage());
    }
    }

I have this exception "org.ksoap2.serialization.SoapPrimitive" when it execute "SoapObject response = (SoapObject)envelope.getResponse();" and I have the follow message:

com.sun.xml.internal.ws.transport.http.HttpAdapter fixQuotesAroundSoapAction
Received WS-I BP non-conformant Unquoted SoapAction HTTP header: http://ws.myfirst.com/getGreeting/

where is the problem? This is the code of my web service: SayHello.java

package com.myfirst.wsServer;
import javax.jws.WebService;

@WebService
public class SayHello { 
    private static final String SALUTATION = "Hello"; 
public String getGreeting( String name ) { 
    return SALUTATION + " " + name; 
}
public String get() { 
    return "ciao!"; 
}
}

RunService.java

package com.myfirst.wsServer;
import javax.xml.ws.Endpoint;

public class RunService { 
public static void main(String[] args) { 
    System.out.println("SayHello Web Service started."); 
    Endpoint.publish("http://localhost:8080/wsServerExample", new SayHello()); 
}
}

GetGreeting.java

package com.myfirst.wsServer.jaxws;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

@XmlRootElement(name = "getGreeting", namespace = "http://wsServer.myfirst.com/")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "getGreeting", namespace = "http://wsServer.myfirst.com/")
public class GetGreeting {
    @XmlElement(name = "arg0", namespace = "")
    private String arg0;

    public String getArg0() {
        return this.arg0;
    }

    public void setArg0(String arg0) {
        this.arg0 = arg0;
    }
}

GetGreetingResponse.java

package com.myfirst.wsServer.jaxws;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

@XmlRootElement(name = "getGreetingResponse", namespace = "http://wsServer.myfirst.com/")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "getGreetingResponse", namespace = "http://wsServer.myfirst.com/")
public class GetGreetingResponse {

    @XmlElement(name = "return", namespace = "")
    private String _return;

    public String getReturn() {
        return this._return;
    }

    public void setReturn(String _return) {
        this._return = _return;
    }
}

Try this. ( with the added line envelope.dotNet = true; )

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM