?? jax.htm
字號(hào):
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0098)http://gceclub.sun.com.cn/staticcontent/html/webservices/web_services_tutorial/jax-rpc.11/11.1.htm -->
<HTML><HEAD><TITLE>Sun eCommunity</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<SCRIPT language=JavaScript>
<!--
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v4.0
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && document.getElementById) x=document.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</SCRIPT>
<SCRIPT language=JavaScript>
var thisButton;
var disabled = false;
function isDisabled(button){
if (!disabled){
button.disabled = true;
disabled = true;
}
thisButton = button;
Timer = setTimeout("setEnable()", 4000);
return disabled;
}
function setEnable(){
thisButton.disabled = false;
disabled = false;
}
</SCRIPT>
<LINK href="jax.files/default.css" type=text/css rel=stylesheet>
<META content="MSHTML 6.00.2800.1492" name=GENERATOR></HEAD>
<BODY bgColor=#ffffff leftMargin=0 topMargin=0
onload="MM_preloadImages('/NASApp/sme/docroot/ecommunity/pics/ar_lg_yell_r_pad1.gif','/NASApp/sme/docroot/ecommunity/pics/ar_lg_red_r_pad1.gif')"
marginwidth="0" marginheight="0"><!-- BEGIN HOMEPAGE CODE --><!-- BEGIN HOMEPAGE TOP NAVIGATION TOOLBAR -->
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD>
<P align=left><SPAN class=sp2><FONT
face=Arial></FONT></SPAN> </P></TD></TR>
<FORM action=http://search.sun.com/search/global/index.jsp>
<TR>
<TD vAlign=center noWrap width="100%">
<DIV class=sitelinks>
<P align=left> 中國 <FONT
face=Arial> | </FONT>熱線電話:<FONT
face=Arial>800-810-3786</FONT></P></DIV></TD>
<TD vAlign=center noWrap>
<DIV class=sitelinks>
<P align=left><A href="http://www.sun.com.cn/howtobuy/">如何購買</A><FONT
face=Arial> | <A href="http://www.sun.com/MySun/">My
Sun</A> | <A
href="http://www.sun.com.cn/worldwide/"></A></FONT><A
href="http://www.sun.com.cn/worldwide/">各地網(wǎng)站</A></P></DIV></TD>
<TD>
<P align=left><FONT
face=Arial> </FONT></P></TD>
<TD vAlign=center>
<P align=left><FONT face=Arial><INPUT class=medium
onfocus="if(this.value==this.defaultValue) this.value='';" size=10
value=搜索 name=qt> <INPUT type=hidden value=PRC name=country> <INPUT
type=hidden value=zh name=language> <INPUT type=hidden value=gb2312
name=charset> <INPUT type=hidden name=variant> </FONT></P></TD>
<TD>
<P align=left><FONT face=Arial> </FONT></P></TD>
<TD vAlign=center align=left>
<P align=left><FONT face=Arial><INPUT class=buttonred onmouseover="this.style.color='#fbe249';" onmouseout="this.style.color='#FFF';" type=submit value=">>" border=0>
</FONT></P></TD>
<TD>
<P align=left><FONT face=Arial><IMG height=1 alt="" src="" width=10
border=0></FONT></P></TD></TR></FORM>
<TR>
<TD>
<P align=left><SPAN class=sp2><FONT
face=Arial></FONT></SPAN> </P></TD></TR></TBODY></TABLE><!-- END HOMEPAGE TOP NAVIGATION TOOLBAR -->
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD height=90>
<DIV align=center>
<TABLE style="BORDER-COLLAPSE: collapse" borderColor=#111111 cellSpacing=8
cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD class=sunblue vAlign=top width="20%" bgColor=#0000ff height=60>
<P align=left><FONT face=Arial><IMG height=38
src="jax.files/logo_sun_home.gif" width=84> </FONT></P></TD>
<TD class=sunyellow vAlign=bottom width="40%" bgColor=#fbe249
height=60>
<P align=left><A
onmouseover="MM_swapImage('Image25211','','http://gceclub.sun.com.cn/NASApp/sme/docroot/ecommunity/pics/ar_lg_red_r_pad1.gif',1)"
onmouseout=MM_swapImgRestore()
href="http://gceclub.sun.com.cn/NASApp/sme/controller/techtopcatquery?cat_id=03"><FONT
face=Arial><IMG height=21 src="jax.files/ar_lg_red_r_pad.gif"
width=24 border=0 name=Image25211></FONT></A><A
onmouseover="MM_swapImage('Image25','','/NASApp/sme/docroot/ecommunity/pics/ar_lg_red_r_pad1.gif',1)"
onmouseout=MM_swapImgRestore()
href="http://gceclub.sun.com.cn/NASApp/sme/controller/sublearning?cat_level=1&cat_id=01"><FONT
face=Arial><IMG height=21 src="jax.files/zxxx0.gif" width=97
border=0></FONT></A></P></TD>
<TD class=sunred vAlign=bottom width="40%" bgColor=#d12124
height=60><P align=left><A
onmouseover="MM_swapImage('Image26111','','http://gceclub.sun.com.cn/NASApp/sme/docroot/ecommunity/pics/ar_lg_yell_r_pad1.gif',1)"
onmouseout=MM_swapImgRestore()
href="http://gceclub.sun.com.cn/NASApp/sme/controller/subresource?cat_level=1&cat_id=02"><IMG
height=21 src="jax.files/ar_lg_yell_r_pad.gif" width=24 border=0
name=Image26111></A><A
onmouseover="MM_swapImage('Image261','','/NASApp/sme/docroot/ecommunity/pics/ar_lg_yell_r_pad1.gif',1)"
onmouseout=MM_swapImgRestore()
href="http://gceclub.sun.com.cn/NASApp/sme/docroot/ecommunity/support/index.jsp"><FONT
face=Arial><IMG height=21 src="jax.files/zczx0.gif" width=97
border=0></FONT></A>
</P></TD></TR></TBODY></TABLE></DIV></TD></TR></TBODY></TABLE>
<TABLE>
<TBODY>
<TR>
<TD vAlign=bottom width=1142>
<TABLE cellSpacing=2 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD vAlign=top width="1%">
<P align=left> </P>
<P align=left> </P></TD>
<TD vAlign=top width="77%">
<DIV>
<DIV class=navbar align=center>
<TABLE dir=ltr cellSpacing=0 cellPadding=0 width="100%"
summary="Navigation bar, includes the book title and navigation buttons"
border=0>
<TBODY>
<TR bgColor=#cccccc>
<TD class=navbartitle align=left abbr=ChapTitle>
<P align=left><FONT
face=Arial> </FONT>用JAX-RPC構(gòu)建Web服務(wù)</P></TD>
<TD vAlign=top align=right abbr=NavButtons><A
href="http://gceclub.sun.com.cn/staticcontent/html/webservices/web_services_tutorial/index.htm"><IMG
height=26 alt="Table of Contents" src="jax.files/toc01.htm"
width=30 border=0> </A><A
href="http://gceclub.sun.com.cn/staticcontent/html/webservices/web_services_tutorial/10/10.2.htm"><IMG
height=26 alt="Previous Chapter" src="" width=30 border=0></A>
<A
href="http://gceclub.sun.com.cn/staticcontent/html/webservices/web_services_tutorial/jax-rpc.11/11.2.htm"><IMG
height=26 alt="Next Chapter" src="" width=30 border=0></A>
</TD></TR></TBODY></TABLE></DIV></DIV>
<DIV>
<DIV>
<TABLE dir=ltr width="100%" summary="Chapter Title" border=0
abbr="ChapTitle">
<COLGROUP width="100%">
<COL id=1 width="100%"></COLGROUP>
<TBODY>
<TR>
<TD>
<P align=left><B><FONT size=6><BR>用</FONT></B><FONT
size=6><B>JAX-RPC構(gòu)建Web服務(wù)</B></FONT></P>
<H5><I><A
href="http://java.sun.com/webservices/docs/1.1/tutorial/doc/Bios.html#wp63559"
target=_blank>Dale Green</A></I></H5>
<P>JAX-RPC表示基于XML遠(yuǎn)程調(diào)用的Java
API。它是用于構(gòu)建Web服務(wù)以及使用遠(yuǎn)程調(diào)用(RPC)和XML客戶端的API。通常用在分布式客戶端/服務(wù)器模式中,RPC機(jī)制使得客戶端可以執(zhí)行其他系統(tǒng)中的過程。</P>
<P>在JAX-RPC中,遠(yuǎn)程過程調(diào)用由SOAP這種基于XML的協(xié)議來表示。SOAP規(guī)范定義了封裝結(jié)構(gòu),編碼規(guī)則,以及遠(yuǎn)程過程調(diào)用和響應(yīng)間的約定。這些調(diào)用和響應(yīng)在http上作為SOAP消息進(jìn)行傳遞。在這個(gè)版本中,JAX-RPC支持SOAP1.1和http1.1。</P>
<P>盡管JAX-RPC建立在復(fù)雜的協(xié)議之上,但API為應(yīng)用程序開發(fā)者隱藏了這一復(fù)雜性。在服務(wù)器端,開發(fā)人員通過定義Java編程語言中接口的方法來指定遠(yuǎn)程過程。開發(fā)者還將編寫一個(gè)或多個(gè)實(shí)現(xiàn)這些方法的類。客戶端程序也是容易編寫的。一個(gè)客戶生成一個(gè)代理,表示服務(wù)的本地對(duì)象,然后簡單的調(diào)用代理上的方法。</P>
<P>使用JAX-RPC,客戶端和web服務(wù)都有巨大的優(yōu)勢——Java編程語言的平臺(tái)無關(guān)性。另外,JAX-RPC是不受限制的:一個(gè)JAX-RPC客戶可以訪問沒有運(yùn)行在Java平臺(tái)的web服務(wù),反之亦然。JAX-RPC很靈活,因?yàn)樗褂昧巳蚓W(wǎng)聯(lián)合會(huì)(W3C)規(guī)定的技術(shù):HTTP,SOPA以及Web服務(wù)描述語言(WSDL)。WSDL為以消息中操作的endpoint集的形勢描述服務(wù)指定了一種XML格式。</P>
<P>如果你是基于XML的RPC(JAX-RPC)的Java
API方面的新手,本章就是一個(gè)起點(diǎn),簡明扼要地描述了JAX-RPC后,本章將介紹如何構(gòu)建一個(gè)簡單的Web服務(wù)及其客戶。對(duì)于高級(jí)用戶,本章繼續(xù)通過代碼列表示例,一步一步的介紹動(dòng)態(tài)客戶的生成。</P>
<H2><A name=jian></A><FONT size=4>簡單示例:HelloWorld</FONT></H2>
<P>本例介紹了如何使用JAX-RPC來生成一個(gè)名為HelloWorld的Web服務(wù)。HelloWorld服務(wù)的遠(yuǎn)程客戶可以調(diào)用sayHello方法,該方法接受一個(gè)字符串參數(shù),然后返回一個(gè)字符串。</P>
<P><B>運(yùn)行期間的HelloWorld</B></P>
<P><A
href="http://gceclub.sun.com.cn/staticcontent/html/webservices/web_services_tutorial/jax-rpc.11/11.1.htm#f11_1">圖11-1</A>顯示了HelloWorld服務(wù)部署后的簡化狀況。下面給出運(yùn)行期間發(fā)生情況的詳細(xì)描述:</P>
<P>1.
為了調(diào)用遠(yuǎn)程過程,HelloClient程序調(diào)用占位程序中的方法,表示遠(yuǎn)程服務(wù)的本地對(duì)象。</P>
<P>2. 占位程序調(diào)用JAX-RPC運(yùn)行系統(tǒng)中的例程。</P>
<P>3.
運(yùn)行系統(tǒng)將遠(yuǎn)程方法調(diào)用轉(zhuǎn)換成SOAP消息,然后以一個(gè)HTTP請求的形式傳輸消息。</P>
<P>4.
當(dāng)服務(wù)器接收到HTTP請求時(shí),JAX-RPC運(yùn)行系統(tǒng)從請求中提取SOAP消息,然后傳送到方法調(diào)用。</P>
<P>5. JAX-RPC運(yùn)行系統(tǒng)調(diào)用約束對(duì)象中的方法。</P>
<P>6. 約束對(duì)象調(diào)用HelloWorld服務(wù)實(shí)現(xiàn)中的方法。</P>
<P>7.
服務(wù)器端運(yùn)行系統(tǒng)將方法響應(yīng)轉(zhuǎn)換成SOAP消息,然后以HTTP響應(yīng)的形式傳輸消息回客戶端。</P>
<P>8.
客戶端,JAX-RPC運(yùn)行系統(tǒng)從HTTP響應(yīng)中提取SOAP消息,然后傳輸?shù)紿elloClient程序的方法響應(yīng)。</P>
<P><A id=f11_1 name=f11_1></A><IMG height=192
src="jax.files/Fig10-1.gif" width=447><BR><STRONG>圖11-1
運(yùn)行期間的HelloWorld示例</STRONG></P>
<P>應(yīng)用程序開發(fā)者只提供由圖11-1描述的堆棧頂層,<A
href="http://gceclub.sun.com.cn/staticcontent/html/webservices/web_services_tutorial/jax-rpc.11/11.1.htm#table11">表11-1</A>顯示了各層的來源。</P>
<P 0718><A name=table11></A><EM>表11-1誰(什么)提供該層</EM></P>
<DIV align=center>
<TABLE cellSpacing=0 cellPadding=0 align=left border=1>
<TBODY>
<TR>
<TD vAlign=top width=299>
<P align=center><STRONG>層</STRONG></P></TD>
<TD vAlign=top width=299>
<P align=center><STRONG>源</STRONG></P></TD></TR>
<TR>
<TD vAlign=top width=299>
<P align=left>HelloClient程序</P>
<P align=left>HelloWorld服務(wù)(定義了接口以及實(shí)現(xiàn)的類)</P></TD>
<TD vAlign=top width=299>
<P align=left>由應(yīng)用程序開發(fā)者提供</P></TD></TR>
<TR>
<TD vAlign=top width=299>
<P align=left>占位程序</P></TD>
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -