加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

用xfire开发webservice客户端

发布时间:2020-12-17 02:35:20 所属栏目:安全 来源:网络整理
导读:1、 ? 安装 jdk jdk 1.6.0 _02 2、 ? 安装 tomcat tomcat 5.5.20 3、 ? 安装 eclipse 下载 eclipse3.2 ,并把他解压缩到 d:/ECLIPSE 目录 1 ???? 安装 tomcatPlugin 插件:解压缩 tomcatPluginV32.zip 包,把解压缩的结果放入 D:/eclipse/plugins 目录 2 ???

1、? 安装jdk

jdk 1.6.0 _02

2、? 安装tomcat

tomcat 5.5.20

3、? 安装eclipse

下载eclipse3.2,并把他解压缩到d:/ECLIPSE目录

1>???? 安装tomcatPlugin插件:解压缩tomcatPluginV32.zip包,把解压缩的结果放入D:/eclipse/plugins目录

2>???? 安装resourcebundleeditor插件:解压缩ResourceBundleEditor_v 0.7.7 .zip包,然后把解压缩的结果放入D:/eclipse/plugins目录

重新启动eclipse/myeclipseresourcebundleeditor进行配置:

进入到eclipsewindow---preference里面,你可以看到下图

?

?

?

所示的界面,设置你自己想要的配置,然后完成,即完成配置

4、? 安装myeclipse

myeclipse5.5

5、? 将更新The XFire Eclipse plugin

The XFire Eclipse plugin provides Eclipse support for XFire's WSDL->Code generator. It requires Eclipse 3.2 and Java 5.

Installing the Plugin

To install the Eclipse XFire plugin:

go to the Help menu,select "Software Updates" and then select "Find and Install."

Select "Search for new features to install" and click Next.

Select "Create New Remote Site" and enter "XFire" as the name and http://dist.codehaus.org/xfire/update/ as the eclipse update site.

Select OK.

Select Finish

?

6、? 新建一个web工程,把WSDL文件拷贝到SRC目录,右击WEB工程=>new=>other

7、? 选择XFIRE文件夹下的code generation from wsdl document,点下一步按钮,出现以下对话框

8、? 选择WSDL URL or path Output directory

9、? 设置客户端代码所在的包

10、????????????? 单击完成按钮,完成客户端框架的生成

11、????????????? 下载XFIREJAR包:xfire-distribution- 1.2.6 解压缩到D

12、????????????? 添加xfireJAR

?????? 鼠标指向工程,点右键,选择Build Path --àAdd Library

?????????????

?? 选择User Libraries 点下一步:

??????

User Libraries

新建用户库XFIRE,引入xfire-distribution- 1.2.6 lib目录下所有的JAR文件和xfire-all-1.2.6.jar,把该用户库引入到WEB工程

13、????????????? src文件夹下建立testmain函数,测试webservice能否正常运行,如下:

?????? package cn.com.cmbc.emu.xi.transferdata;

?

import java.lang.reflect.Proxy;

import org.codehaus.xfire.client.Client;

import org.codehaus.xfire.client.XFireProxy;

?

?

public class testmain {

?

?????? ?????? /**

?????? ????? * @测试webservice服务器端能否正常运行

?????? ????? */

?????? ?????? public static void main(String[] args) {

????????????? //预定义客户端输入对象

????????????? CMBCLOSBPDT cmbcl;

?????? //建立客户端对象

CMBC_LOSTST_OUTServiceClient client =new CMBC_LOSTST_OUTServiceClient();

//建立服务器端对象

?????? CMBC_LOSTST_OUT service = client.getCMBC_LOSTST_OUTPort();

//引入org.codehaus.xfire.client.Client包,设置认证用户名和密码

Client client1 = e((XFireProxy)Proxy.getInvocationHandler(service)).getClient();

client1.setProperty(client1.getOutChannel().USERNAME,"user");?? client1.setProperty(client1.getOutChannel().PASSWORD,"222221");

//根据ObjectFactory类,创建客户端输入对象

?????? ObjectFactory of = new ObjectFactory() ;

?????? cmbcl=of.createCMBCLOSBPDT();????????

??????? //设置输入对象中属性的值

?????? cmbcl.setBUSINESSPARTNER("aaaaaaaaaa");

?????? //得到webservice的返回对象的name属性

??????? System.out.println(service.cMBC_LOSTST_OUT(cmbcl).getNAME());

?????? System.out.println("test client completed");

?????? }

}

14、????????????? 运行上程序,如果能在控制台打印出name属性的值,那么webservice调用成功

?

说明:可以把testmain类改造成javabean,实现webservice客户端与web工程的集成,即在IE中动态设置调用对象的值,并显示webservice的返回结果,在集成过程中要注意,JSP页面和javabean之间最好是以对象为单位传值,即JSP传给Javabean客户端输入对象,Javabeanwebservice服务器端交互后,返回服务器端返回对象,JSP解析返回对象

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读