Java Reference
In-Depth Information
first XML tag within a node given a specific tag name. Note that you need to parse some of
the information you receive from the server. For example, since the server returns the string
"172.19 - 211.98" to specify the annual range, you need to split up this string and parse it using
Double.parseDouble() to store it in your variables. Note also the use of the SimpleDateFormat
class to parse a string to a Date object.
4. StockServiceClient contains most of the same logic you've seen before to communicate with the
SOAP service.
5.
Finally, your now nimble main method just invokes the StockServiceClient and StockFactory
classes to do the heavy lifting. You have neatly separated all aspects of this program—the
domain logic ( Stock ), the service interaction logic ( StockServiceClient ), and the parsing logic
( StockFactory ). If you want, you can continue to expand on this program some more. For exam-
ple, try expanding the main method to take a list of stock symbols, retrieve their information, and
show a ranking based on price/earnings ratio.
Accessing SOAp Services with JAX‐WS with WSDL
You have seen how to access a web service by constructing SOAP request messages manually.
However, this method assumes that you are aware of the endpoints the service provides, the opera-
tions, and the parameters to be passed.
To overcome this issue, most SOAP‐based web services provide a so‐called WSDL file. WSDL, or
“Web Services Description Language,” is an XML format for describing network services and their
endpoints, together with the operation they support and the arguments they expect. You can use the
information stored in such files to allow JAX‐WS to do a lot of the work for you.
Let's take another look at the Stock Quote service page at WebserviceX.NET :
http://www.webservicex.net/WS/WSDetails.aspx?CATID=2&WSID=9 . The description mentions
that a WSDL file is provided at http://www.webservicex.net/stockquote.asmx?WSDL , which
you can request with your web browser, and indeed looks like an XML document containing the
following:
<wsdl:definitions xmlns:tm=" http://microsoft.com/wsdl/mime/textMatching/"
xmlns:soapenc=" http://schemas.xmlsoap.org/soap/encoding/"
xmlns:mime=" http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:tns=" http://www.webserviceX.NET/"
xmlns:soap=" http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:s=" http://www.w3.org/2001/XMLSchema"
xmlns:soap12=" http://schemas.xmlsoap.org/wsdl/soap12/"
xmlns:http=" http://schemas.xmlsoap.org/wsdl/http/"
xmlns:wsdl=" http://schemas.xmlsoap.org/wsdl/"
targetNamespace=" http://www.webserviceX.NET/">
<wsdl:types>
<s:schema elementFormDefault="qualified"
targetNamespace=" http://www.webserviceX.NET/">
<s:element name="GetQuote">
<s:complexType>
 
Search WWH ::




Custom Search