1.新建一个webservice project,如图所示
2.点击下一步出现,如下对话框
3.接着点下一步
4.下面点击finish项目就自动生成了,结构如下
5.下面先来写接口和实现类
- package org.lxh.dao;
- public interface SayHello {
- public void say(String name);
- }
package org.lxh.dao;
public interface SayHello {
public void say(String name);
}
- package org.lxh.impl;
- import org.lxh.dao.SayHello;
- public class Person implements SayHello{
- public void say(String name) {
- // TODO Auto-generated method stub
- System.out.println("你好:"+name);
- }
- }
package org.lxh.impl;
import org.lxh.dao.SayHello;
public class Person implements SayHello{
public void say(String name) {
// TODO Auto-generated method stub
System.out.println("你好:"+name);
}
}
6.配置services.xml
- <?xml version="1.0" encoding="UTF-8"?>
- <beans xmlns="http://xfire.codehaus.org/config/1.0">
- <service>
- <name>myxfire</name>
- <serviceClass>org.lxh.dao.SayHello</serviceClass>
- <implementationClass>org.lxh.impl.Person</implementationClass>
- <style>wrapped</style>
- <use>literal</use>
- <scope>application</scope>
- </service>
- </beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xfire.codehaus.org/config/1.0">
<service>
<name>myxfire</name>
<serviceClass>org.lxh.dao.SayHello</serviceClass>
<implementationClass>org.lxh.impl.Person</implementationClass>
<style>wrapped</style>
<use>literal</use>
<scope>application</scope>
</service>
</beans>
name就是webservice的名称,大家可以随意
7.点击下面飘红的图标,输入http://localhost:8089/usexfire/services/myxfire?WSDL。点下go就会出现如下界面
其中amy就是我的参数。控制台就会输出内容如下所示
到这里程序就写好了,大家自己可以写客户端程序在测试下。我给大家个截图大家参考下,记得引入XFire HTTP Client Libraries
大家改改接口名或类名就可以用了。