用xfire实现基于java的webservice接口调用

步骤一:

        开发工具: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测试类,结果:


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值