📄 jax.htm
字号:
<!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/">各地网站</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构建Web服务</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构建Web服务</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远程调用的Java
API。它是用于构建Web服务以及使用远程调用(RPC)和XML客户端的API。通常用在分布式客户端/服务器模式中,RPC机制使得客户端可以执行其他系统中的过程。</P>
<P>在JAX-RPC中,远程过程调用由SOAP这种基于XML的协议来表示。SOAP规范定义了封装结构,编码规则,以及远程过程调用和响应间的约定。这些调用和响应在http上作为SOAP消息进行传递。在这个版本中,JAX-RPC支持SOAP1.1和http1.1。</P>
<P>尽管JAX-RPC建立在复杂的协议之上,但API为应用程序开发者隐藏了这一复杂性。在服务器端,开发人员通过定义Java编程语言中接口的方法来指定远程过程。开发者还将编写一个或多个实现这些方法的类。客户端程序也是容易编写的。一个客户生成一个代理,表示服务的本地对象,然后简单的调用代理上的方法。</P>
<P>使用JAX-RPC,客户端和web服务都有巨大的优势——Java编程语言的平台无关性。另外,JAX-RPC是不受限制的:一个JAX-RPC客户可以访问没有运行在Java平台的web服务,反之亦然。JAX-RPC很灵活,因为它使用了全球网联合会(W3C)规定的技术:HTTP,SOPA以及Web服务描述语言(WSDL)。WSDL为以消息中操作的endpoint集的形势描述服务指定了一种XML格式。</P>
<P>如果你是基于XML的RPC(JAX-RPC)的Java
API方面的新手,本章就是一个起点,简明扼要地描述了JAX-RPC后,本章将介绍如何构建一个简单的Web服务及其客户。对于高级用户,本章继续通过代码列表示例,一步一步的介绍动态客户的生成。</P>
<H2><A name=jian></A><FONT size=4>简单示例:HelloWorld</FONT></H2>
<P>本例介绍了如何使用JAX-RPC来生成一个名为HelloWorld的Web服务。HelloWorld服务的远程客户可以调用sayHello方法,该方法接受一个字符串参数,然后返回一个字符串。</P>
<P><B>运行期间的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服务部署后的简化状况。下面给出运行期间发生情况的详细描述:</P>
<P>1.
为了调用远程过程,HelloClient程序调用占位程序中的方法,表示远程服务的本地对象。</P>
<P>2. 占位程序调用JAX-RPC运行系统中的例程。</P>
<P>3.
运行系统将远程方法调用转换成SOAP消息,然后以一个HTTP请求的形式传输消息。</P>
<P>4.
当服务器接收到HTTP请求时,JAX-RPC运行系统从请求中提取SOAP消息,然后传送到方法调用。</P>
<P>5. JAX-RPC运行系统调用约束对象中的方法。</P>
<P>6. 约束对象调用HelloWorld服务实现中的方法。</P>
<P>7.
服务器端运行系统将方法响应转换成SOAP消息,然后以HTTP响应的形式传输消息回客户端。</P>
<P>8.
客户端,JAX-RPC运行系统从HTTP响应中提取SOAP消息,然后传输到HelloClient程序的方法响应。</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
运行期间的HelloWorld示例</STRONG></P>
<P>应用程序开发者只提供由图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服务(定义了接口以及实现的类)</P></TD>
<TD vAlign=top width=299>
<P align=left>由应用程序开发者提供</P></TD></TR>
<TR>
<TD vAlign=top width=299>
<P align=left>占位程序</P></TD>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -