1

我使用本教程http://www.ibm.com/developerworks/webservices/tutorials/ws-eclipse-javase1/ws-eclipse-javase1-pdf.pdf在 eclipse 中编写了一个简单的 web 服务。现在我必须为这个 Web 服务编写客户端。这是我的代码:

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());
    }
    }

当它执行“SoapObject response = (SoapObject)envelope.getResponse();”时,我有这个异常“org.ksoap2.serialization.SoapPrimitive” 我有以下消息:

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

问题出在哪里?这是我的网络服务的代码: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!"; 
}
}

运行服务.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;
    }
}
4

1 回答 1

0

尝试这个。(添加线envelope.dotNet = true;

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
于 2012-08-25T13:09:05.240 回答