XFire的调用方式是:
String wsdl = "http://192.168.1.112:8088/testService?wsdl";
try {
Client client = new Client(new URL(wsdl));
String result = client.invoke("test", new Object[]{"hello"});
} catch (MainformedURLException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
服务端的代码如:
接口:
public interface ITest {
public String test(String str);
}
实现类:
@WebService(name="test", serviceName = "test")
@SOAPBinding(stype = SOAPBinding.Style.RPC)
public class TestImpl implements ITest {
@Override
public String test(String str) {
System.out.println(str);
}
}
解决办法:
在服务端的实现类上加上:@SOAPBinding(stype = SOAPBinding.Style.RPC) ,如果不写的情况下默认的类型是Document,至于RPC和Document的区别大家可以参考其他Webservice资料,不过两种类型各有优点和缺点。
代码变成:
@WebService(name="test", serviceName = "test")
@SOAPBinding(stype = SOAPBinding.Style.RPC)
public class TestImpl implements ITest {
@Override
public String test(String str) {
System.out.println(str);
}
}
JDK1.6自带的Webservice非常强大,而且不用我们额外引入jar包,而且应该将来会越来越强大,所以推荐大家使用。
本文介绍了一种解决WebService客户端传递参数为空的问题。通过调整服务端的SOAP绑定样式为RPC风格,成功解决了XFire客户端调用JDK1.6自带WebService服务端时参数丢失的情况。
4495

被折叠的 条评论
为什么被折叠?



