瘋狂
STANDING ON THE SHOULDERS OF GIANTS
posts - 481, comments - 486, trackbacks - 0, articles - 1
BlogJava
::
首頁
::
新隨筆
::
聯(lián)系
::
聚合
::
管理
JAX-WS weService實(shí)例 c/s形式
Posted on 2010-01-13 23:22
瘋狂
閱讀(2503)
評(píng)論(0)
編輯
收藏
所屬分類:
webservice
Java SE 6封裝了JAX-WS(Java API for XML-Web Services),而JAX-WS同時(shí)支持基于SOAP的Web服務(wù)和REST風(fēng)格的Web服務(wù),以下是個(gè)人寫的一個(gè)實(shí)例:
首先是服務(wù)端:
首先創(chuàng)建java項(xiàng)目或者web項(xiàng)目都可;
首先編寫service端接口,WebServerInterface(必須已接口形式發(fā)布)
@WebService(serviceName
=
"
testserver
"
,targetNamespace
=
"
http://testserver.com
"
)
@SOAPBinding(style
=
SOAPBinding.Style.RPC)
public
interface
WebServerInterface
{
@WebMethod
public
TestUser getAllTestUsersByUserName(String userName);
}
TestUser.java
package
com.server;
public
class
TestUser
{
private
int
id;
private
String usetName;
private
String pwd;
public
int
getId()
{
return
id;
}
public
void
setId(
int
id)
{
this
.id
=
id;
}
public
String getUsetName()
{
return
usetName;
}
public
void
setUsetName(String usetName)
{
this
.usetName
=
usetName;
}
public
String getPwd()
{
return
pwd;
}
public
void
setPwd(String pwd)
{
this
.pwd
=
pwd;
}
}
實(shí)現(xiàn)類:
@WebService(endpointInterface
=
"
com.server.WebServerInterface
"
)
public
class
WebServerInterfaceImpl
implements
WebServerInterface
{
@Override
public
TestUser getAllTestUsersByUserName(String userName)
{
//
TODO Auto-generated method stub
return
TestUserManager.getUserByName(userName);
}
}
接下來是TestUserManager.java(用戶管理類)
public
class
TestUserManager
{
public
static
List
<
TestUser
>
users;
static
{
users
=
new
ArrayList
<
TestUser
>
();
for
(
int
i
=
0
;i
<=
10
;i
++
)
{
TestUser testUser
=
new
TestUser();
testUser.setId(i);
testUser.setUsetName(
"
userName_
"
+
i);
testUser.setPwd(
"
pwd_
"
+
i);
users.add(testUser);
}
}
public
static
TestUser getUserByName(String userName)
{
for
(TestUser testUser:users)
{
if
(testUser.getUsetName().equals(userName))
{
return
testUser;
}
}
return
null
;
}
}
這樣server就編寫好了 然后就是發(fā)布server:當(dāng)然如果是web項(xiàng)目的話可以通過servlet發(fā)布 當(dāng)然要設(shè)置:
load-on-startup
為1 在tomcat啟動(dòng)時(shí)初始化發(fā)布
public
static
void
main(String[] args)
{
Endpoint.publish(
"
http://127.0.0.1:10100/mywebserver
"
,
new
WebServerInterfaceImpl());
}
運(yùn)行后webserver就發(fā)布好了 可以同ie訪問
接下來是客戶端的訪問:
客戶端可以同eclipse通過wsdl的url來自動(dòng)生成
也可以自己實(shí)現(xiàn)
例如:
URL url = new URL("http://127.0.0.1:10100/mywebserver?wsdl");
QName qname = new QName("
Service service = Service.create(url, qname);
WebServerInterface = service.getPort(WebServerInterface .class);
然后就可以操作了
代碼下載:
/Files/freeman1984/src_server.rar
/Files/freeman1984/src_client.rar
新用戶注冊(cè)
刷新評(píng)論列表
只有注冊(cè)用戶
登錄
后才能發(fā)表評(píng)論。
網(wǎng)站導(dǎo)航:
博客園
IT新聞
Chat2DB
C++博客
博問
管理
相關(guān)文章:
我應(yīng)該采用哪一種 WSDL 樣式?(轉(zhuǎn)載)
webservice b/s (jax-ws 2.1)
xmlrpc介紹和使用
axis客戶端簡單實(shí)現(xiàn)
spring cxf
JAX-WS weService實(shí)例2
PHPRPC
JAX-WS weService實(shí)例 c/s形式
axis webService發(fā)布webservice和client的簡單實(shí)現(xiàn)
Powered by:
BlogJava
Copyright © 瘋狂
日歷
<
2010年1月
>
日
一
二
三
四
五
六
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
5
6
公告
公眾號(hào):
QQjava交流群:
51374316
留言簿
(11)
給我留言
查看公開留言
查看私人留言
隨筆分類
all 生活雜談(16)
android(18)
apache項(xiàng)目(20)
chart(1)
concurrent(5)
database(70)
dwr(3)
flex(6)
hibernate(25)
java (135)
javafx(2)
javascript
java安全(8)
java性能(19)
jbpm(1)
jquery(4)
linux(17)
lucene(1)
netty(3)
nginx(1)
others(2)
questions(31)
questions_hander(28)
spring(32)
struts(9)
swing
UML(2)
unix(13)
web(45)
webservice(9)
xml(5)
敏捷(6)
方法論(28)
架構(gòu)(21)
測試(1)
緩存
網(wǎng)絡(luò)通訊(9)
讀代碼(6)
項(xiàng)目管理(19)
相冊(cè)
我的相冊(cè)
搜索
積分與排名
積分 - 2843936
排名 - 2
最新隨筆
1.? 后續(xù)內(nèi)容請(qǐng)移步公眾號(hào)“duomi88”
2.?Netty百萬級(jí)推送服務(wù)(轉(zhuǎn))
3.?Netty 概述(轉(zhuǎn))
4.?Netty優(yōu)雅退出機(jī)制和原理(轉(zhuǎn))
5.?使用JavaMail SearchTerm 收取郵件
6.?JAVA Thread Dump 分析綜述
7.?oracle 索引字段包含date類型,使用spring jdbc更新時(shí)不走索引,而是走table access full的問題
8.?FTP主動(dòng)模式和被動(dòng)模式的比較(轉(zhuǎn)載)
9.?關(guān)于java RMI在多網(wǎng)卡下(或者啟動(dòng)360,百度,騰訊等wifi共享下)無法連接問題(java.rmi.ConnectException: Connection refused to host: xx)
10.?(轉(zhuǎn))Oracle數(shù)據(jù)庫如何授權(quán)收費(fèi)(Database Licensing)
11.? 成功的 Web 應(yīng)用系統(tǒng)性能測試 (轉(zhuǎn)載)
12.?It is indirectly referenced from required .class file異常
13.?(轉(zhuǎn))svn cleanup failed–previous operation has not finished; run cleanup if it was interrupted
14.?automation服務(wù)器不能創(chuàng)建對(duì)象 解決辦法
15.?ERROR: transport error 202: gethostbyname: unknown host 解決辦法
16.?JavaScript 跨瀏覽器事件處理(轉(zhuǎn))
17.?函數(shù)聲明 VS 函數(shù)表達(dá)式(轉(zhuǎn))
18.?ORA-06548錯(cuò)誤
19.?項(xiàng)目規(guī)劃與管理記錄2
20.?tmpFile.renameTo(classFile) failed
21.?redhat6.4 64位安裝rlwrap
22.?ora-01031:insufficient privileges
23.?mysql遠(yuǎn)程連接問題 Access denied for user 'root'@' ip ' (using password: YES)
24.?dbcp重連(轉(zhuǎn))
25.?解決Vmware Workstation上安裝Linux系統(tǒng)不能SSH遠(yuǎn)程連接的問題
26.?URL最大長度限制(轉(zhuǎn))
27.?用MyEclipse測試發(fā)送email時(shí)報(bào)java.lang.NoClassDefFoundError: com/sun/mail/util/LineInputStream
28.?我應(yīng)該采用哪一種 WSDL 樣式?(轉(zhuǎn)載)
29.?linux 掛載ntfs usb 出現(xiàn)mount: unknown filesystem type 'ntfs'
30.?11g oracle 用戶密碼過期問題
最新評(píng)論
1.?re: Oracle物化視圖創(chuàng)建全過程(轉(zhuǎn))
評(píng)論內(nèi)容較長,點(diǎn)擊標(biāo)題查看
--ya
2.?re: Oracle物化視圖創(chuàng)建全過程(轉(zhuǎn))
評(píng)論內(nèi)容較長,點(diǎn)擊標(biāo)題查看
--ya
3.?re: 11g oracle 用戶密碼過期問題
問問
--是是是
4.?re: mysql遠(yuǎn)程連接問題 Access denied for user 'root'@' ip ' (using password: YES)
asdfsadf
--asdf
5.?re: struts(il8n)實(shí)現(xiàn)國際化的一個(gè)例子
在啥地方
--正常
主站蜘蛛池模板:
亚洲男人天堂2020
|
免费a级毛片视频
|
成年女人毛片免费播放人
|
精品国产免费观看一区
|
亚洲AV无码乱码精品国产
|
亚洲丁香婷婷综合久久
|
男男gvh肉在线观看免费
|
久久久久免费视频
|
久久大香香蕉国产免费网站
|
1000部拍拍拍18勿入免费凤凰福利
|
亚洲精品天天影视综合网
|
亚洲色成人WWW永久网站
|
日本一区免费电影
|
亚洲一区无码精品色
|
亚洲五月激情综合图片区
|
国产成人亚洲综合一区
|
一级毛片高清免费播放
|
疯狂做受xxxx高潮视频免费
|
最近2019中文免费字幕在线观看
|
深夜免费在线视频
|
日韩免费无码视频一区二区三区
|
亚洲午夜久久影院
|
亚洲JLZZJLZZ少妇
|
女人隐私秘视频黄www免费
|
久久久www成人免费毛片
|
亚洲一级Av无码毛片久久精品
|
亚洲首页在线观看
|
日本黄页网址在线看免费不卡
|
人人爽人人爽人人片A免费
|
99在线免费观看视频
|
手机看片久久国产免费
|
亚洲av无码无在线观看红杏
|
亚洲AV无码一区二区三区牛牛
|
黄视频在线观看免费
|
免费观看成人毛片a片2008
|
区久久AAA片69亚洲
|
亚洲色最新高清av网站
|
国产成人无码区免费内射一片色欲
|
午夜免费福利在线观看
|
婷婷亚洲久悠悠色悠在线播放
|
蜜桃传媒一区二区亚洲AV
|