漫步红林
品味技术与生活之间的差距,追求代码与国画之间的艺术.
BlogJava
联系
聚合
管理
0 Posts :: 28 Stories :: 2 Comments :: 0 Trackbacks
留言簿
给我留言
查看公开留言
查看私人留言
文章分类
(26)
Ajax/JavaScript
C#
C++
Corejava(3)
DOM/XML
EJB3(2)
ERP(1)
Flex
Hibernate
J2EE
JDBC(1)
JNA
JNI(2)
JSP/Servlet(1)
Linux(3)
MySQL(1)
Oracle(2)
RMI(1)
Socket
Spring(1)
Structs
Thread(1)
Tomcat(2)
WebService & SOA(4)
WebWork
专业术语解析(1)
文章档案
(28)
2009年3月 (5)
2009年2月 (23)
搜索
积分与排名
积分 - 19434
排名 - 1765
最新评论
1. re: XFire 之简单开发Webservice
谢谢 帮了一个大忙 呵呵
--sl
2. re: MySql 备份与整理问题
兄弟直接写个脚本,内容是mysqldump 备份语句
直接运行脚本就行了,不需要写代码那么麻烦吧?而且你还可以通过crontab设定脚本执行时间,自动备份,轻松。
--路过
XFire 之简单开发Webservice
在一次偶然的机会,我接触XFire,在接触XFire之前,曾经用过Axis2,总感觉Axis2很麻烦,所以找了XFire。虽然XFire现在已经被CXF取代,但在现在已经开发的项目中,还是有不少使用XFire来实现Web Service的。今天来谈谈用XFire开发客户端。
一、服务提供者告诉你interface,你可以使用如下三种方式来开发:
YourService即是服务提供者告诉给你的一个interface(当然,也可以根据WSDL的定义,自己定义一个同样的interface)。
1. 简单的方式
1
Service serviceModel
=
new
ObjectServiceFactory().create(YourService.
class
);
2
YourService service
=
(YourService)
3
new
XFireProxyFactory().create(serviceModel,
"
http://your/remote/url
"
);
4
2. JSR 181注释的方式
1
Service serviceModel
=
new
AnnotationServiceFactory().create(YourService.
class
);
2
YourService client
=
(YourService)
new
XFireProxyFactory().create(serviceModel,
"
http://your/remote/url
"
);
3. 混合方式
1
Service serviceModel
=
new
AnnotationServiceFactory(
2
new
Jsr181WebAnnotations(),
3
XFireFactory.newInstance().getXFire().getTransportManager(),
4
new
AegisBindingProvider(
new
JaxbTypeRegistry())).create(YourService.
class
);
5
二,通过WSDL创建一个动态的客户端,如下:
1
package
test;
2
3
import
java.net.MalformedURLException;
4
import
java.net.URL;
5
6
import
org.codehaus.xfire.client.Client;
7
public
class
DynamicClientTest
{
8
public
static
void
main(String[] args)
throws
MalformedURLException,
9
Exception
{
10
Client client
=
new
Client(
new
URL(
11
"
http://localhost:8080/xfiretest/services/TestService?wsdl
"
));
12
Object[] results
=
client
13
.invoke(
"
sayHello
"
,
new
Object[]
{
"
Firends
"
}
);
14
System.out.println(results[
0
]);
15
16
}
17
}
18
三,使用ANT工具或命令行通过WSDL生成一个客户端:
1,使用ANT生成客户端,ANT脚本如下:
1
<?
xml version
=
"
1.0
"
?>
2
<
project name
=
"
wsgen
"
default
=
"
wsgen
"
basedir
=
"
.
"
>
3
<
path id
=
"
classpathId
"
>
4
<
fileset dir
=
"
./WebRoot/WEB-INF/lib
"
>
5
<
include name
=
"
*.jar
"
/>
6
</
fileset
>
7
</
path
>
8
<
taskdef classpathref
=
"
classpathId
"
name
=
"
wsgen
"
classname
=
"
org.codehaus.xfire.gen.WsGenTask
"
>
9
</
taskdef
>
10
<
target name
=
"
wsgen
"
description
=
"
generate client
"
>
11
<
wsgen outputDirectory
=
"
./src/
"
wsdl
=
"
abc.wsdl
"
binding
=
"
xmlbeans
"
package
=
"
com.abc.p
"
overwrite
=
"
true
"
/>
12
</
target
>
13
</
project
>
14
请注意,脚本中有一个参数binding,可以指定如下两种不同的方式:
(1) jaxb(Java Architecture for XML Binding,
https://jaxb.dev.java.net/
):使用此种方式时,会自动生成更多的Request和Resopnse类。
(2)xmlbeans
调用方式如下:
1
AbcServiceClient client
=
new
AbcServiceClient();
2
String url
=
"
http://localhost:8080/xfireTest/services/TestService
"
;
3
String result
=
client.getAbcPort(url).sayHello(
"
Robin
"
);
4
2,使用命令生成客户端的命令如下:
1
gpath
=
xfire
-
all
-
1.2
-
SNAPSHOT.jar:ant
-
1.6
.
5
.jar:jaxb
-
api
-
2
.0EA3.jar:stax
-
api
-
1.0
.
1
.jar:jdom
-
1.0
.jar:jaxb
-
impl
-
2
.0EA3.jar\
2
:jaxb
-
xjc
-
2.0
-
ea3.jar:wstx
-
asl
-
2.9
.
3
.jar:commons
-
logging
-
1.0
.
4
.jar:activation
-
1.1
.jar:wsdl4j
-
1.5
.
2
.jar:XmlSchema
-
1.0
.
3
.jar:xfire
-
jsr181
-
api
-
1.0
-
M1.jar;
3
4
java
-
cp $gpath org.codehaus.xfire.gen.WsGen
-
wsdl http:
//
localhost:8080/xfire/services/Bookservice?wsdl -o . -p pl.tomeks.client -overwrite true
posted on 2009-02-22 17:23
苦瓜
阅读(355)
评论(1)
编辑
收藏
所属分类:
WebService & SOA
Feedback
#
re: XFire 之简单开发Webservice
2009-03-03 18:24
sl
谢谢 帮了一个大忙 呵呵
回复
更多评论
新用户注册
刷新评论列表
只有注册用户
登录
后才能发表评论。
网站导航:
博客园
IT新闻
Chat2DB
C++博客
博问
相关文章:
SOA框架的六个不完美之处
WebService视点
XFire 入门
XFire 之简单开发Webservice
Powered by:
BlogJava
Copyright © 苦瓜