⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lib0097.html

📁 This handbook is a concise guide to architecting, designing, and building J2EE applications. It guid
💻 HTML
字号:
<html>
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<head>
<title>Web Services</title>
<link rel="STYLESHEET" type="text/css" href="images/xpolecat.css">
<link rel="STYLESHEET" type="text/css" href="images/ie.content.css">
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr><td><div STYLE="MARGIN-LEFT: 0.15in;"><a href="toc.html"><img src="images/teamlib.gif" width="62" height="15" border="0" align="absmiddle"  alt="Team LiB"></a></div></td>
<td align="right"><div STYLE="MARGIN-LEFT: 0.15in;">
<a href="LiB0096.html"><img src="images/previous.gif" width="62" height="15" border="0" align="absmiddle" alt="Previous Section"></a>
<a href="LiB0098.html"><img src="images/next.gif" width="41" height="15" border="0" align="absmiddle" alt="Next Section"></a>
</div></td></tr></table>
<br>
<div class="chapter">
<a name="ch14"></a>
<div class="section">
<h2 class="first-section-title"><a name="468"></a><a name="ch14lev1sec3"></a>Web Services</h2><a name="469"></a><a name="IDX-194"></a>
<p class="para">All the major container vendors are providing ways to configure stateless session beans so they can be called as a Web service using the SOAP protocol. This is the easiest and fastest way by far for you to get a Web service up and going quickly, because all it requires on the server side is a configuration change. The guidelines given for session beans earlier in the chapter apply to Web services directly.</p>
<p class="para">Unfortunately, all the Web service client code that I've seen differs slightly for each SOAP service provider or vendor. <a class="internaljump" href="#ch14list04">Listing 14.4</a> is a sample using Apache, which appears to be popular, but you should consider this a "concept" example that you may not be able to take literally.</p>
<div class="example">
<span class="example-title"><span class="example-titlelabel">Listing 14.4: </span>Sample Apache SOAP Web Service Client</span><a name="470"></a><a name="ch14list04"></a>
<div class="formalbody">
<table class="BlueLine" border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td bgcolor="000080" class="bluecell"><font size="2" face="Arial" color="010100"><b><img src="_.gif" width="1" height="2" alt="Start example" border="0"></b></font></td>
</tr>
</table>
<pre class="literallayout">
   1:package book.sample.client.web;
   2:
   3:import book.sample.vo.PurchaseOrderVO;
   4:// some code omitted
   5:
   6:public class PoClient
   7:{
   8:    public PoClient() throws ServiceException
   9:    {
  10:      _webService = new Service();
  11:      _webServiceCall = _webService.createCall();
  12:
  13:      _webServiceCall.setTargetEndpointAddress(
  14:          PO_SERVICE_URL);
  15:    }
  16:
  17:    public void recordPurchaseOrder(
  18:         PurchaseOrderVO order)
  19:         throws     InsufficientCreditException,
  20:                     InternalApplicationException,
  21:                     RemoteException
  22:    {
  23:        QName recordPOQName =
  24:            new QName("recordPurchaseOrder");
  25:
  26:        Object[] args = new Object[1];
  27:        args[0] = order.describeAsXMLDocument();
  28:        _webServiceCall.setOperationName(
  29:            recordPOQName);
  30:
  31:        Object ret = null;<a name="471"></a><a name="IDX-195"></a>
  32:        ret = _webServiceCall.invoke(args);
  33:    }
  34:}
</pre>
<table class="BlueLine" border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td bgcolor="000080" class="bluecell"><font size="2" face="Arial" color="010100"><b><img src="_.gif" width="1" height="2" alt="End example" border="0"></b></font></td>
</tr>
</table>
<table class="BlankSpace" border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td height="16"></td>
</tr>
</table>
</div>
</div>
<p class="para">
<i class="emphasis">Source: </i>/src/book/sample/client/web/PoClient.java</p>
<p class="para">Notice that <a class="internaljump" href="#ch14list04">listing 14.4</a> passes XML text as an argument instead of as a value object directly. It certainly could have passed the value object directly. With Web services, passing complex data types is a little less straightforward than it should be, but it is possible. The primary reason to pass XML document text instead is performance.</p>
<p class="para">
<a href="LiB0099.html#477" target="_parent" class="chapterjump">Cohen (2003)</a> has done some performance and scalability tests comparing various types of argument patterns for Web services. The practice of passing XML text as a string argument falls under the category of what he calls SOAP Remote Procedure Call Literal Encoding (SOAP RPC-literal). Compared with passing the value object directly, this type of code is easier to implement, is faster, and scales better.</p>
<p class="para">Furthermore, passing XML text as a string argument is less sensitive to changes in SOAP vendors. Complex data types depend on serialization (and deserialization) techniques to encode content. Because vendors use different encoding techniques, the serializer on the client and server should be from the same vendor. Passing XML text (as string data) bypasses potential vendor-switching costs down the road.</p>
<p class="last-para">CementJ facilitates the practice of passing XML text in Web services. Value objects that extend <span class="fixed">ValueObject</span> can easily be translated to XML text via the method <span class="fixed">encodeAsXML()</span>. I would like to offer a <span class="fixed">decodeFrom-XML()</span> in the future, but reconstituting a class from an XML document with enough reliability for production systems is a challenging task.</p>
</div>
</div><br>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr><td><div STYLE="MARGIN-LEFT: 0.15in;"><a href="toc.html"><img src="images/teamlib.gif" width="62" height="15" border="0" align="absmiddle"  alt="Team LiB"></a></div></td>
<td align="right"><div STYLE="MARGIN-LEFT: 0.15in;">
<a href="LiB0096.html"><img src="images/previous.gif" width="62" height="15" border="0" align="absmiddle" alt="Previous Section"></a>
<a href="LiB0098.html"><img src="images/next.gif" width="41" height="15" border="0" align="absmiddle" alt="Next Section"></a>
</div></td></tr></table>
</body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -