在eclipse中新建一个webservice工程,目的是引入Xfile的jar包,增加service.xml配置,以及在web.xml中新增一个servlet。
修改service.xml文件,增加服务节点:
<service>
<name>HelloService</name>
<serviceClass>com.Hello</serviceClass>
<implementationClass>com.HelloService</implementationClass>
</service>
布署完成后,可以通过地址:
http://localhost:8080/webservice/services/HelloService?wsdl 查看web服务中可调用的接口。
public interface Hello {
public int add(int i,int j);
public void print(String s);
}
public class HelloService implements Hello {
public int add(int i,int j) {
return i+j;
}
public void print(String s) {
// TODO Auto-generated method stub
System.out.println("--->"+s);
}
}
Xfile调用:首先在eclipse中导入xfile core 1.2.jar和xfile http client.jar
调用代码如下:
Service serModel = new ObjectServiceFactory().create(Hello.class);
XFireProxyFactory factory = new XFireProxyFactory(XFireFactory.newInstance().getXFire());
String helloURL = "http://localhost:8080/webservice/services/HelloService";
try {
Hello h = (Hello) factory.create(serModel,helloURL);
h.print(" liping");
} catch (MalformedURLException e) {
e.printStackTrace();
}
axis调用:首先在eclipse中导入axis包,调用代码如下:
String helloURL = "http://localhost:8080/webservice/services/HelloService";
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(helloURL));
call.setOperationName("print");
call.invoke(new Object[] {" liping"});
webservice
最新推荐文章于 2025-12-21 17:48:37 发布
本文介绍如何在Eclipse中创建WebService项目,并通过Xfile和Axis两种方式调用WebService服务。示例中创建了一个简单的HelloService服务,实现加法运算和字符串打印功能。
11万+

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



