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/

問題はどこだ?これは私の Web サービスのコードです: 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;
    }
}
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 に答える