📄 jaxrpc4.html
字号:
<service name="MyHelloService" targetNamespace="urn:Foo" typeNamespace="urn:Foo" packageName="helloservice"> <interface name="helloservice.HelloIF"/> </service></configuration><a name="wp117423"> </a></pre></div><a name="wp117424"> </a><p class="pBody">The <code class="cCode">config.xml-interface</code> file tells <code class="cCode">wscompile</code> to create a WSDL file with the following information:</p><div class="pSmartList1"><ul class="pSmartList1"><a name="wp117425"> </a><div class="pSmartList1"><li>The service name is <code class="cCode">MyHelloService</code>.</li></div><a name="wp117426"> </a><div class="pSmartList1"><li>The WSDL namespace is <code class="cCode">urn:Foo</code>. (To understand this namespace, you need to be familiar with WSDL technology. See <a href="JAXRPC2.html#wp79859">Types Supported By JAX-RPC</a>) </li></div><a name="wp117430"> </a><div class="pSmartList1"><li>The classes for the <code class="cCode">MyHelloService</code> are in the <code class="cCode">helloservice</code> package.</li></div><a name="wp117431"> </a><div class="pSmartList1"><li>The service endpoint interface is <code class="cCode">helloservice.HelloIF</code>.</li></div></ul></div><a name="wp117438"> </a><h3 class="pHeading2">Packaging the Service</h3><a name="wp117439"> </a><p class="pBody">Behind the scenes, a JAX-RPC Web service is actually a servlet. Because a servlet is a Web component, to package the service you run the New Web Component wizard of the <code class="cCode">deploytool</code> utility. During this process the wizard performs the following tasks.</p><div class="pSmartList1"><ul class="pSmartList1"><a name="wp117440"> </a><div class="pSmartList1"><li>Creates the Web application deployment descriptor</li></div><a name="wp117441"> </a><div class="pSmartList1"><li>Creates a WAR file</li></div><a name="wp117442"> </a><div class="pSmartList1"><li>Adds the deployment descriptor and service files to the WAR file</li></div></ul></div><a name="wp117443"> </a><p class="pBody">To start the New Web Component wizard, select File<span style="font-family: Symbol"><img src="images/arrwrite.gif" border="0" alt="Right Arrow"></span>New<span style="font-family: Symbol"><img src="images/arrwrite.gif" border="0" alt="Right Arrow"></span>Web Component. The wizard displays the following dialog boxes.</p><div class="pSmartList1"><ol type="1" class="pSmartList1"><a name="wp117444"> </a><div class="pSmartList1"><li>Introduction dialog box </li></div><div class="pSmartList2"><ol type="a" class="pSmartList2"><a name="wp117445"> </a><div class="pSmartList2"><li>Read the explanatory text for an overview of the wizard's features. </li></div><a name="wp117446"> </a><div class="pSmartList2"><li>Click Next.</li></div></ol></div><a name="wp117447"> </a><div class="pSmartList1"><li>WAR File dialog box</li></div><div class="pSmartList2"><ol type="a" class="pSmartList2"><a name="wp117448"> </a><div class="pSmartList2"><li>Select the button labelled Create New Stand-Alone WAR Module.</li></div><a name="wp117449"> </a><div class="pSmartList2"><li>In the WAR Location field, navigate to <code class="cVariable"><INSTALL></code><code class="cCode">/j2eetutorial14/examples/jaxrpc/helloservice/.</code></li></div><a name="wp117450"> </a><div class="pSmartList2"><li>In the WAR Display Field, enter <code class="cCode">MyHelloService</code>.</li></div><a name="wp117451"> </a><div class="pSmartList2"><li>Click Edit.</li></div><a name="wp117452"> </a><div class="pSmartList2"><li>In the tree under Available Files, locate the <code class="cVariable"><INSTALL></code>/<code class="cCode">j2eetutorial14</code>/<code class="cCode">examples/jaxrpc/helloservice/</code> directory.</li></div><a name="wp117453"> </a><div class="pSmartList2"><li>Select the <code class="cCode">build</code> subdirectory.</li></div><a name="wp117454"> </a><div class="pSmartList2"><li>Click Add. </li></div><a name="wp117455"> </a><div class="pSmartList2"><li>Click OK.</li></div><a name="wp117456"> </a><div class="pSmartList2"><li>Click Next.</li></div></ol></div><a name="wp117457"> </a><div class="pSmartList1"><li>Choose Component Type dialog box</li></div><div class="pSmartList2"><ol type="a" class="pSmartList2"><a name="wp117458"> </a><div class="pSmartList2"><li>Select the Web Services Endpoint button.</li></div><a name="wp117459"> </a><div class="pSmartList2"><li>Click Next.</li></div></ol></div><a name="wp117460"> </a><div class="pSmartList1"><li>Choose Service dialog box</li></div><div class="pSmartList2"><ol type="a" class="pSmartList2"><a name="wp117461"> </a><div class="pSmartList2"><li>In the WSDL File combo box, select <code class="cCode">WEB-INF/wsdl/MyHelloService.wsdl</code>.</li></div><a name="wp117462"> </a><div class="pSmartList2"><li>In the Mapping File combo box, select <code class="cCode">build/mapping.xml</code>.</li></div><a name="wp117463"> </a><div class="pSmartList2"><li>Click Next.</li></div></ol></div><a name="wp118973"> </a><div class="pSmartList1"><li>Component General Properties dialog box</li></div><div class="pSmartList2"><ol type="a" class="pSmartList2"><a name="wp118974"> </a><div class="pSmartList2"><li>In the Service Endpoint Implementation combo box, select <code class="cCode">helloservice.HelloImpl</code>.</li></div><a name="wp118980"> </a><div class="pSmartList2"><li>Click Next.</li></div></ol></div><a name="wp117464"> </a><div class="pSmartList1"><li>Web Service Endpoint dialog box</li></div><div class="pSmartList2"><ol type="a" class="pSmartList2"><a name="wp117465"> </a><div class="pSmartList2"><li>In the Service Endpoint Interface combo box, select <code class="cCode">helloservice.HelloIF</code>.</li></div><a name="wp117466"> </a><div class="pSmartList2"><li>In the Namespace field, select <code class="cCode">urn:Foo</code>.</li></div><a name="wp117467"> </a><div class="pSmartList2"><li>In the Local Part field, select <code class="cCode">HelloIFPort</code>.</li></div><a name="wp117468"> </a><div class="pSmartList2"><li>deploytool will enter a default Endpoint Address URI <code class="cCode">HelloImpl</code> in this dialog. This endpoint address <em class="cEmphasis">must</em> be updated in the next section. </li></div><a name="wp121732"> </a><div class="pSmartList2"><li>Click Next.</li></div><a name="wp117472"> </a><div class="pSmartList2"><li>Click Finish.</li></div></ol></div></ol></div><a name="wp117474"> </a><h3 class="pHeading2">Specifying the Endpoint Address</h3><a name="wp117475"> </a><p class="pBody">To access <code class="cCode">MyHelloService</code>, the tutorial clients will specify this service endpoint address URI:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">http://localhost:8080/hello-jaxrpc/hello<a name="wp117476"> </a></pre></div><a name="wp117477"> </a><p class="pBody">The <code class="cCode">/hello-jaxrpc</code> string is the context root of the servlet that implements MyHelloService. The <code class="cCode">/hello</code> string is the servlet alias. To specify the endpoint address, you set the context root and alias as follows:</p><div class="pSmartList1"><ol type="1" class="pSmartList1"><a name="wp117478"> </a><div class="pSmartList1"><li>In <code class="cCode">deploytool</code>, select <code class="cCode">MyHelloService</code> in the tree.</li></div><a name="wp117479"> </a><div class="pSmartList1"><li>Select the General tab.</li></div><a name="wp117480"> </a><div class="pSmartList1"><li>In the Context Root field, enter <code class="cCode">/hello-jaxrpc</code>.</li></div><a name="wp117481"> </a><div class="pSmartList1"><li>In the tree, select <code class="cCode">HelloImpl</code>.</li></div><a name="wp117482"> </a><div class="pSmartList1"><li>Select the Aliases tab.</li></div><a name="wp117483"> </a><div class="pSmartList1"><li>In the Component Aliases table, add <code class="cCode">/hello</code>. (Don't forget the forward slash.)</li></div><a name="wp117484"> </a><div class="pSmartList1"><li>In the Endpoint tab, select <code class="cCode">hello</code> for the Endpoint Address in the Sun-specific Settings Frame.</li></div><a name="wp117485"> </a><div class="pSmartList1"><li>Select File<span style="font-family: Symbol"><img src="images/arrwrite.gif" border="0" alt="Right Arrow"></span>Save.</li></div></ol></div><a name="wp82513"> </a><h3 class="pHeading2">Deploying the Service</h3><a name="wp117490"> </a><p class="pBody">In deploytool, perform these steps:</p><div class="pSmartList1"><ol type="1" class="pSmartList1"><a name="wp117491"> </a><div class="pSmartList1"><li>In the tree, select <code class="cCode">MyHelloService</code>.</li></div><a name="wp117492"> </a><div class="pSmartList1"><li>Select Tools<span style="font-family: Symbol"><img src="images/arrwrite.gif" border="0" alt="Right Arrow"></span>Deploy.</li></div></ol></div><a name="wp117493"> </a><p class="pBody">Now you are ready to create a client that accesses this service.</p> </blockquote> <img src="images/blueline.gif" width="550" height="8" ALIGN="BOTTOM" NATURALSIZEFLAG="3" ALT="Divider"> <table width="550" summary="layout" id="SummaryNotReq1"> <tr> <td align="left" valign="center"> <font size="-1"> <a href="http://java.sun.com/j2ee/1.4/download.html#tutorial" target="_blank">Download</a> <br> <a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/faq.html" target="_blank">FAQ</a> <br> <a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/history.html" target="_blank">History</a> </td> <td align="center" valign="center"><a accesskey="p" href="JAXRPC3.html"><img id="LongDescNotReq1" src="images/PrevArrow.gif" width="26" height="26" border="0" alt="Prev" /></a><a accesskey="c" href="J2EETutorialFront.html"><img id="LongDescNotReq1" src="images/UpArrow.gif" width="26" height="26" border="0" alt="Home" /></a><a accesskey="n" href="JAXRPC5.html"><img id="LongDescNotReq3" src="images/NextArrow.gif" width="26" height="26" border="0" alt="Next" /></a><a accesskey="i" href="J2EETutorialIX.html"></a> </td> <td align="right" valign="center"> <font size="-1"> <a href="http://java.sun.com/j2ee/1.4/docs/api/index.html" target="_blank">API</a> <br> <a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/search.html" target="_blank">Search</a> <br> <a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/sendusmail.html" target="_blank">Feedback</a></font> </font> </td> </tr> </table> <img src="images/blueline.gif" width="550" height="8" ALIGN="BOTTOM" NATURALSIZEFLAG="3" ALT="Divider"><p><font size="-1">All of the material in <em>The J2EE(TM) 1.4 Tutorial</em> is <a href="J2EETutorialFront2.html">copyright</a>-protected and may not be published in other workswithout express written permission from Sun Microsystems.</font> </body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -