android的web服务客户端
我使用本教程在eclipse中编写了一个简单的Web服务。现在我必须为这个web服务编写客户端。 这是我的代码:android的web服务客户端,android,eclipse,web-services,ksoap,Android,Eclipse,Web Services,Ksoap,我使用本教程在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 stati
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;
}
}
试试这个。(添加了行envelope.dotNet=true;
)
在这种情况下,您能告诉我您的服务在WSDL中的定义吗?也许把它附在问题本身上?:)以及用于定义服务的java代码。可能有两个问题。您的请求转换会弹出一些不需要的字符,这会破坏SOAP\u操作。另外,可能是您在@WebParam中缺少targetNamespace属性。我不太确定这一点,但getGreetingResponse.java中@XmlElement(name=“return”,namespace=”“)这一行的namespace字段是否应该留空?如果我更改它,情况也是一样的
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);