使用工具:MyEclipse8.5+tomcat6
1. file-->new Web Service Project,填好项目名称,framework选择XFire,如图一
图一
2. next-->next选择下面三项如图二
图二
3.选择finish,出现如下所示项目如图三
图三
4.在src下新建package(webservice),接口HelloWorld。其实现类HelloWorldImpl如图四
图四
5.impl代码
package webservice;
publicclass HelloWorldImpl implements HelloWorld {
public String sayHelloWithParameter(String str) {
// TODO Auto-generated method stub
return"hello"+str;
}
publicvoid sayHelloWithoutParameter() {
// TODO Auto-generated method stub
}
}
6.配置WebService下services.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xfire.codehaus.org/config/1.0">
<service>
<name>Hello</name>
<namespace>http://localhost:8080/Hello/</namespace>
<serviceClass>webservice.HelloWorld</serviceClass>
<implementationClass>webservice.HelloWorldImpl</implementationClass>
</service>
</beans>
7.输入http://localhost:8080/Hello/services如图五
图五
8.点击wsdl,如图六
图六
9.test代码
package webservice;
import java.net.MalformedURLException;
import org.codehaus.xfire.XFireFactory;
import org.codehaus.xfire.client.XFireProxyFactory;
import org.codehaus.xfire.service.Service;
import org.codehaus.xfire.service.binding.ObjectServiceFactory;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
Service srvcModel = new ObjectServiceFactory().create(HelloWorld.class);
XFireProxyFactory factory = new XFireProxyFactory(XFireFactory.newInstance().getXFire());
System.out.println(factory);
String helloWorldURL = "http://localhost:8080/Hello/services/Hello";
try {
HelloWorld srvc = (HelloWorld) factory.create(srvcModel,helloWorldURL);
String result = srvc.sayHelloWithParameter("rrr");
System.out.println(result);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
输出
org.codehaus.xfire.client.XFireProxyFactory@c24c0
hellorrr