步骤一:
开发工具:eclipse
jdk:1.5+ tomcat: 5.0+
xfire相应jar包下载(百度搜索有很多)
步骤二:
建立java工程,写下面的接口,和类
<接口类:>
package com.taitai.qiqi;
public interface QiqiService {
String add(String xx);
void del();
}
<实现类:>
package com.tatai.qiqi;
public class QiqiServiceImpl implements QiqiService {
public String add(String xx) {
System.out.println("进入add:");
String yy = xx+"webservice success";
return yy;
}
public void del() {
// TODO Auto-generated method stub
}
}
<测试类:>
package com.taitai.qiqi;
import java.net.MalformedURLException;
import java.net.URL;
import org.codehaus.xfire.XFireFactory;
import org.codehaus.xfire.client.Client;
import org.codehaus.xfire.client.XFireProxyFactory;
import org.codehaus.xfire.service.Service;
import org.codehaus.xfire.service.binding.ObjectServiceFactory;
import com.taikang.qiqi.QiqiService;
public class QiqiTest2 {
public static void main(String[] args) throws MalformedURLException, Exception {
Service s=new ObjectServiceFactory().create(QiqiService.class);
XFireProxyFactory xf=new XFireProxyFactory(XFireFactory.newInstance().getXFire());
String url="http://10.136.12.66:8080/eciPreInsure/services/qiqiEntrance";
try
{
QiqiService qq=(QiqiService) xf.create(s,url);
String st=qq.add("lizhe");
System.out.print("VVVVVVVVVVVVVVVVVVVVV"+st);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
步骤三:配置service.xml
位置:
内容:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xfire.codehaus.org/config/1.0">
<!-- qiqi -->
<service>
<name>qiqiEntrance</name>
<serviceClass>com.taikang.qiqi.QiqiService</serviceClass>
<implementationClass>
com.taikang.qiqi.QiqiServiceImpl
</implementationClass>
<style>wrapped</style>
<use>literal</use>
<scope>application</scope>
</service>
</beans>
步骤四:
测试:可以调自己,也可以调别人的,只要改变ip就行,但是注意,如果是调别人的webservice接口,别人必须要有你的接口类:就是上面的 QiqiService.java
启动tomcat,运行java测试类,结果: