• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Web Services Part 2
 

Web Services Part 2

on

  • 2,881 views

 

Statistics

Views

Total Views
2,881
Views on SlideShare
2,880
Embed Views
1

Actions

Likes
1
Downloads
258
Comments
0

1 Embed 1

http://www.slideshare.net 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Web Services Part 2 Web Services Part 2 Presentation Transcript

    • Create a simple web-services (say hello)
      • Choose web-project named it HelloWebService
      • Choose java class say “Hello” within “mypackage” package
      • package mypackage;
      • import javax.jws.WebService;
      • @WebService() // @WebService() annotation to the Hello.java will expose all public methods of the Hello class to be exposed as Web service operations. public class Hello {
      • public Hello() { }
      • // Business method we want to expose as Web service operation
      • public String sayHello(String name){
      • return "Hello " + name + "!";
      • }
      • }
      • Right click on the project and choose deploy for deploy the project.
      • Test the Web service : Expand Web services and right click Hello Web service node and select Test Web Service
      • Observe HelloService Web Service Tester page is displayed.
      • Type in your name, Niyaz Rao in this example. Click sayHello button
      • Observe that a new page is displayed with the result of the testing
      • Observe that the SOAP message request and response are also displayed
      • Click backward button of the browser to go the previous page
      • Click WSDL File link .observer it
      • Observe the URL of the WSDL document is http://localhost:8080/HelloWebService/HelloService?WSDL. 
      • We will use this URL later on when you create the corresponding Web service client.
    • Creating a client for consuming web-service
      • Choose java project called “HelloWebServiceClient”
      • Right click HelloWebServiceClient and select Web Services and under File Types,select WebService Client.
      • Observe WSDL and Client Location pane gets displayed
      • Select WSDL URL and specify the location of the WSDL http://localhost:8080/HelloWebService/HelloService?WSDL
      • For the Package field, type in mypackage.
      • We can also select Project option (instead of WSDL URL option)
      • package hellowebserviceclient; public class Main {     public static void main(String[] args) {         try
      • {
      • // Call Web Service Operation
      • mypackage.HelloService service = new mypackage.HelloService(); mypackage.Hello port = service.getHelloPort();   java.lang.String result = port.sayHello(“niyaz rao”);  System.out.println("Result = "+result);         }
      • catch (Exception ex) {        }               } }
      • OR Move your cursor under the line of  within the main() method.
      • Right click and select Web Service Client Resources->Call Web Service Operation
    • Web Service Description language (WSDL 1.2)
    • Introduction
      • WSDL (Web Services Description Language) is an XML-based language for describing Web services and how to access them.
      • WSDL is written in XML
      • WSDL is an XML document
      • WSDL is used to describe Web services
      • WSDL is also used to locate Web services
      • WSDL is not yet a W3C standard
    •  
    • The WSDL Document Structure
      • A WSDL document describes a web service using these major elements
      DEFINES ELEMENTS The communication protocols used by the web service <binding> The data types used by the web service <types> The messages used by the web service <message> The operations performed by the web service <portType>
      • The main structure of the WSDL document is looks like :
      • <definitions>
      • <types>
      • definition of types........
      • </types>
      • <message>
      • definition of a message....
      • </message>
      • <portType>
        • definition of a port.......
      • </portType>
      • <binding>
        • definition of a binding....
      • </binding>
      • </definitions>
      • <portType> :
        • It describes a web service, the operations that can be performed, and the messages that are involved.
        • The <portType> element can be compared to a function library (or a module, or a class) in a traditional programming language .
      • <message>
        • The <message> element defines the data elements of an operation
        • Each message can consist of one or more parts. The parts can be compared to the parameters of a function call in a traditional programming language.
      • <types>
        • The <types> element defines the data type that are used by the web service
      • <binding>
        • The <binding> element defines the message format and protocol details for each port.
      • <message name=&quot;getTermRequest&quot;>
      • <part name=&quot;term&quot; type=&quot;xs:string&quot;/>
      • </message>
      • <message name=&quot;getTermResponse&quot;>
        • <part name=&quot;value&quot; type=&quot;xs:string&quot;/>
      • </message>
      • <portType name=&quot;glossaryTerms&quot;> <operation name=&quot;getTerm&quot;> <input message=&quot;getTermRequest&quot;/> <output message=&quot;getTermResponse&quot;/> </operation> </portType>
      • In this example the <portType> element defines &quot;glossaryTerms&quot; as the name of a port , and &quot;getTerm&quot; as the name of an operation
    • WSDL Ports
      • The <portType> element is the most important WSDL element.
      • It defines a web service , the operations that can be performed, and the messages that are involved
      • Operation type : The request-response type is the most common operation type, but WSDL defines four types:
      • One-way :The operation can receive a message but will not return response
      • Request-response :The operation can receive a request and will return a response
      • Solicit-response: The operation can send a request and will wait for a response
      • Notification: The operation can send a message but will not wait for a response
      • <message name=&quot;newTermValues&quot;>
      • <part name=&quot;term&quot; type=&quot;xs:string&quot;/>
      • <part name=&quot;value&quot; type=&quot;xs:string&quot;/>
      • </message>
      • <portType name=&quot; glossaryTerms &quot;>
      • <operation name=&quot; setTerm &quot;>
      • <input name=&quot;newTerm&quot; message=&quot; newTermValues &quot;/> </operation>
      • </portType >
      • In this example the port &quot;glossaryTerms&quot; defines a one-way operation called &quot;setTerm&quot;. The &quot;setTerm&quot; operation allows input of new glossary terms messages using a &quot;newTermValues&quot; message with the input parameters &quot;term&quot; and &quot;value&quot;. However, no output is defined for the operation.
      • Request-response model :
      • <message name=&quot;getTermRequest&quot;>
      • <part name=&quot;term&quot; type=&quot;xs:string&quot;/>
      • </message>
      • <message name=&quot;getTermResponse&quot;>
      • <part name=&quot;value&quot; type=&quot;xs:string&quot;/>
      • </message>
      • <portType name=&quot;glossaryTerms&quot;> <operation name=&quot;getTerm&quot;> <input message=&quot;getTermRequest&quot;/> <output message=&quot;getTermResponse&quot;/> </operation> </portType>
    • WSDL Binding
      • WSDL bindings defines the message format and protocol details for a web service.
      • Consider a request-response model :
      • <message name=&quot;getTermRequest&quot;>
      • <part name=&quot;term&quot; type=&quot;xs:string&quot;/>
      • </message>
      • <message name=&quot;getTermResponse&quot;>
      • <part name=&quot;value&quot; type=&quot;xs:string&quot;/>
      • </message>
      • <portType name=&quot;glossaryTerms&quot;> <operation name=&quot;getTerm&quot;> <input message=&quot;getTermRequest&quot;/> <output message=&quot;getTermResponse&quot;/> </operation> </portType>
      • <binding type =&quot;glossaryTerms&quot; name =&quot;b1&quot;>
      • <soap:binding style =&quot;document&quot; transport =&quot;http://schemas.xmlsoap.org/soap/http&quot; />
      • <operation> <soap:operation soapAction =&quot;http://example.com/getTerm&quot;/>
      • <input> <soap:body use=&quot;literal&quot;/> </input>
      • <output> <soap:body use=&quot;literal&quot;/></ output>
      • </operation>
      • </binding>
      • The binding element has two attributes - the name attribute and the type attribute.The name attribute (you can use any name you want) defines the name of the binding, and the type attribute points to the port for the binding, in this case the &quot;glossaryTerms&quot; port.
      • Soap:binding :
      • style attribute :
        • indicates whether the operation is RPCoriented(messages containing parameters and return values) or document-oriented (message containing document(s)).by default it is document
      • transport attribute :
        • indicates which transport to use :
          • http://schemas.xmlsoap.org/soap/http (for HTTP) http://schemas.xmlsoap.org/soap/smtp (for SMTP)
      • soapAction attribute:
        • specifies the value of the SOAPAction header for this operation
      • Soap:body :
        • Provides information on how to assemble the different message parts inside the Body element
        • Used in both RPC-oriented and document-oriented messages
      • Use attribute : &quot;literal|encoded“
        • literal
          • parts define the concrete schema of the message XML document fragment can be validated against its XML schema
        • Encoded
          • Indicates whether the message parts are encoded using some encoding rules
    • RPC vs. Document style Blind trust Trusted enviroment Between enterprise Within enterprise complex Simple point-to-point Over internet Typically within internet schema Function call Buisness document Procedural call DOCUMENT RPC
    • Creating WSDL File manually (using Net-Beans)
      • In this example we create a WSDL document for operation add of two integers
      • Create web project say “MyWSDLProject” , in this choose new WSDL document(XML) called “MyWSDL”
      • In the folder option choose Web/WEB-INF folder
      • For the Operation Name, enter add.
      • For the Message Part Name, change part1 to x.
      • For the Element Or Type, click ...
      • Chose int from Built-in Types.
      • Add y as int type.
      • For Output, change part1 to result.
      • Change the Element Or Type field to xsd:int.
      • Click Next
      • Choose RPC Literal
      • Right click myWSDLPortType and select Add->Operation
      • For Operation Name, enter hello.
      • Change Message Part Name of the Input section to name.
      • Change the Element Or Type to xsd:string.
      • Change Message Part Name of the Output section to resultHello
      • Change the Element Or Type to xsd:string.
      • Click Source tab window and see the source of the WSDL file
    • Universal Description, Discovery and Integration (UDDI)
    • Introduction
      • UDDI is a platform-independent framework for describing services, discovering businesses, and integrating business services by using the Internet.
        • UDDI stands for Universal Description, Discovery and Integration
        • UDDI is a directory for storing information about web services
        • UDDI is a directory of web service interfaces described by WSDL
        • UDDI communicates via SOAP
        • UDDI is built into the Microsoft .NET platform
      • Before UDDI, there was no Internet standard for businesses to reach their customers and partners with information about their products and services. Nor was there a method of how to integrate into each other's systems and processes
      • Problems the UDDI specification can help to solve:
        • Making it possible to discover the right business from the millions currently online
        • Defining how to enable commerce once the preferred business is discovered
        • Reaching new customers and increasing access to current customers
        • Expanding offerings and extending market reach
        • Solving customer-driven need to remove barriers to allow for rapid participation in the global Internet economy
        • Describing services and business processes programmatically in a single, open, and secure environment
    • How can UDDI be Used
      • Example :
      • If the industry published an UDDI standard for flight rate checking and reservation, airlines could register their services into an UDDI directory.
      • Travel agencies could then search the UDDI directory to find the airline's reservation interface.
      • When the interface is found, the travel agency can communicate with the service immediately because it uses a well-defined reservation interface
    • Who is Supporting UDDI?
      • UDDI is a cross-industry effort driven by all major platform and software providers like Dell , Fujitsu , HP , Hitachi , IBM , Intel , Microsoft , Oracle , SAP , and Sun , as well as a large community of marketplace operators, and e-business leaders.
      • Over 220 companies are members of the UDDI community .
    • Business supporting data
      • White pages
        • address, contact, and known identifiers
      • Yellow pages
        • industrial categorizations
        • Industry: NAICS (Industry codes - US Govt.)
        • Product/Services: UN/SPSC (ECMA)
        • Location: Geographical taxonomy
      • Green pages
        • technical information about services
    • UDDI Data type
      • Buisness Entity Data type ( white page ):
        • Top-level data structure that holds descriptive information about a business entity
        • Service descriptions and technical information are expressed within a businessEntity
    • Annotations Used in JAX-WS
      • @WebService
        • Marks a Java class as implementing a Web Service, or a Java interface as defining a Web Service interface.
        • Attributes
          • name
          • serviceName
          • targetNamespace
          • wsdlLocation
      • @WebMethod
        • Customizes a method that is exposed as a Web Service operation
        • The method is not required to throw java.rmi.RemoteException.
        • Attributes
          • Action
          • operationName
      • @WebParam
        • Customizes the mapping of an individual parameter to a Web Service message part and XML element.
        • Attributes
          • name
          • targetNamespace
    • Creating a web-service
      • package org.me.calculator;
      • import javax.jws.WebMethod;
      • import javax.jws.WebParam;
      • import javax.jws.WebService;
      • @WebService()
      • public class CalculatorWS {
      • @WebMethod
      • public int add(@WebParam(name = &quot;i&quot;) int i, @WebParam(name = &quot;j&quot;) int j) {
      • int k = i + j;
      • return k;
      • } }
      • Same steps as before :
      • Create a servlet client:
      • import javax.xml.ws.WebServiceRef;
      • import org.me.calculator.CalculatorWSService;
      • public class myservlet extends HttpServlet {
      • @WebServiceRef(wsdlLocation = &quot;http://localhost:8080/CalculateWSapplication/CalculatorWSService?wsdl &quot;)
      • private CalculatorWSService service;
      • Public void doGet(…………. )
      • {
      • try {
      • org.me.calculator.CalculatorWS port = service.getCalculatorWSPort();
      • int i = 0,,j=0;
      • int result = port.add(6, 4);
      • out.println(&quot;Result = &quot;+result);
      • } catch (Exception ex) { }
      • }
    • Problem
      • Create a Web-Service for calculating interest ( principal, rate and time) as input parameter .
        • Create a simple java client for accessing this service
        • Create a servlet client for access this service
        • Create a JSP client for access this service
    • Java Api for XML registries (JAXR)
    • Registry and registry operation
      • To submit and store shared information
      • To identify, name, describe, classify,relate, group, and associate shared information
      • To query, discover and retrieve shared information
    • Registry use-case Scenario in B2B
    • History of Registry specification eCo Framework UDDI JAXR ISO 11179 OASIS Registry ebXML Registry
    • What is JAXR
      • Standard Java™ API for performing registry operations over diverse set of registries
      • A unified information model for describing business registry content
      • Provides multi-layered API abstractions
      • Enabling technology for web services in the J2EE™ platform
    • Any Client to Any Registry Interoperability Registry Browsers J2EE Components Desktop Applications ebXML UDDI JAXR API Other DIVERSE CLIENT DIVERSE REGISTRY PROVIDER
    • JAXR Architectural Roles
      • Registry Provider
      • – Provides an implementation of a registry specification
      • – Is not expected to implement JAXR specification
      • – examples: UDDI registry, ebXML registry
      • JAXR Provider
      • – Implements JAXR specification
      • – Typically functions as facade to existing registry providers
      • – example: JAXR reference implementation
      • JAXR Client
      • – Uses JAXR APIs to access services provided by JAXR Provider
    • JAXR Architecture JAXR Client UDDI Provider Other Provider eBXML Provider JAXR PLUGGABLE PROVIDER UDDI eBXML OTHER CAPABILITY SPECIFIC INTERFACE DIVERSE REGISTRIES
    • JAXR Architecture
      • Remote communication occurs between JAXR provider and Registry providers
        • Security concerns (over remote communication) need to be addressed
        • Use registry provider specific protocols
          • UDDI message over SOAP for UDDI registry provider
          • ebXML MS for ebXML reg/rep
      • JAXR client and JAXR provider are expected to be co-located in a same JVM in most implementations
    • Java API for XML-based RPC (JAX-RPC)
    • Remote procedural call (RPC)
      • RMI
      • CORBA
      • COM
      • Common agenda :
        • Common Interface between client and Server
        • Stub for client, Tie/skeleton for server
        • On-the-wire protocol needs to be agreed upon
      • RPC Example : Java RMI
      • Remote procedure calls (RPCs) are the precursors to modern Web services that are based on the Simple Object Access Protocol (SOAP) or Representational State Transfer (REST).
      • Because all of the Java™ platform's Web service APIs are built on the concepts introduced in RPC, understanding the Java APIs for XML-Based RPC (JAX-RPC) is an almost mandatory step for writing efficient and effective Web services in the Java language.
    • RPC Example : JAX-RPC
      • Common Interface : Each client and server having a common interface in distributed environment
      • Service is described in IDL ( Interface Description Language )
        • IDL of CORBA service
        • Java RMI interface in RMI (Language specific)
        • WSDL for Web service
      • Concept of XML based RPC :
        • Uses Standards based on XML
          • SOAP is the “protocol”
          • WSDL is the IDL
        • Any communication protocol can be used as a transport
          • e.g.) HTTP, SMTP, FTP etc.
    • What is JAX-RPC
      • Java™ API for XML-based RPC
        • Web Services operations are performed by exchanging SOAP 1.1 messages
      • Services are described using WSDL
        • WSDL is the contract between service provider and client (only contract needed)
      • Web service endpoints and clients use JAX-RPC programming model
      • Key technology for Web Services in the J2EE 1.4 platform
    • JAX-RPC Architecture WSDL Document JAX-RPC Client Generated Code Container Container Client-side JAX-RPC Runtime System Server-side JAX-RPC Runtime System JAX-RPC Service Endpoint SOAP HTTP
    • Build an RPC service and client using JAX-RPC (using Apache Axis)
      • This Example divided into following module :
        • getting and installing JAX-RPC
        • configuring it in Tomcat server
        • building a server-side RPC receiver
        • client-side application.
      • 1. Install Tomcat 6.x
      • 2. Check your tomcat installation.
      • 3. Download Apache Axis 1.4
        • JAX-RPC isn't part of a standard Java distribution, you'll need to do a little work to get it installed and configured.
        • Download axis-bin-1_4.zip file
        • Expand the package you've downloaded. You'll get a directory named something like axis-1_4 .
      • 4. There is no need to install anything for JAX-RPC
        • Like the Java API for XML Binding (JAXB) or the Java API for XML Processing (JAXP), and even standard APIs like JDBC, JAX-RPC is really an API specification
        • The classes and interfaces included with JAX-RPC are all in the javax.xml.rpc package and several subpackages:
      • Apache Axis comes with a sample Web application that can be deployed on any servlet container. You simply need to copy the Axis Web application into the location in your servlet container where Web applications reside, and test out Axis.
      • 5 .Copy the Axis folder into web-apps directory of Tomcat installation
      • 6. Restart your Tomcat Server
      • 7. Open the browser and type :
      • http://localhost:8080/axis
    •  
      • Validation page for Apache Axis (with several errors)
      • This will display you all necessary jar file
      • Some error message and Warning message is also display
      • 8. Download all missing jar files :
        • Activation.jar
        • Mail.jar etc.
      • 9. Copy these jar files to the lib folder of servlet engine
        • C:Program FilesApache Software FoundationTomcat 6.0lib
      • Again restart your server and do the same , this time make sure there is no errors. Also copy the tools.jar from jdk1.6 installation to the above lib folder
      • Here we are making sample application for searching books.
      • 10 . First we create a java programme later we convert that programme into service.
      • Define Class and methods calls
      • import java.util.*;
      • public class BookSearcher
      • {
      • private Map books;
      • public BookSearcher()
      • {
      • books = new HashMap();
      • // for example purposes
      • addBooks();
      • }
      • public void setBooks(Map books) {
      • this.books = books;
      • }
      • public void addBook(String title, List keywords) {
      • books.put(title, keywords);
      • }
      • public void addKeyword(String title, String keyword) {
      • List keywords = (List)books.get(title);
      • if (keywords != null) {
      • keywords.add(keyword);
      • } else {
      • keywords = new LinkedList();
      • keywords.add(keyword);
      • books.put(title, keywords);
      • }
      • }
      • public List getKeywords(String title) {
      • return (List)books.get(title);
      • }
      • public List search(String keyword) {
      • List results = new LinkedList();
      • for (Iterator i = books.keySet().iterator(); i.hasNext(); ) {
      • String title = (String)i.next();
      • List keywords = (List)books.get(title);
      • if (keywords.contains(keyword)) {
      • results.add(title);
      • }
      • }
      • return results;
      • }
      • private void addBooks() { // add some sample data
      • List keywords = new LinkedList();
      • keywords.add(&quot;presentation&quot;);
      • keywords.add(&quot;Keynote&quot;);
      • keywords.add(&quot;PowerPoint&quot;);
      • keywords.add(&quot;design&quot;);
      • addBook(&quot;Presentation Zen&quot;, keywords);
      • List keywords2 = new LinkedList();
      • keywords2.add(&quot;presentation&quot;);
      • keywords2.add(&quot;user interface design&quot;);
      • keywords2.add(&quot;pictures&quot;);
      • keywords2.add(&quot;visuals&quot;);
      • addBook(&quot;The Back of the Napkin&quot;, keywords2);
      • List keywords3 = new LinkedList();
      • keywords3.add(&quot;marketing&quot;);
      • keywords3.add(&quot;business&quot;);
      • keywords3.add(&quot;commercials&quot;);
      • keywords3.add(&quot;consumers&quot;);
      • addBook(&quot;Purple Cow&quot;, keywords3);
      • List keywords4 = new LinkedList();
      • keywords4.add(&quot;marketing&quot;);
      • keywords4.add(&quot;business&quot;);
      • keywords4.add(&quot;notecards&quot;);
      • keywords4.add(&quot;design&quot;);
      • keywords4.add(&quot;visuals&quot;);
      • keywords4.add(&quot;pictures&quot;);
      • keywords4.add(&quot;humor&quot;);
      • addBook(&quot;Indexed&quot;, keywords4);
      • List keywords5 = new LinkedList();
      • keywords5.add(&quot;marketing&quot;);
      • keywords5.add(&quot;business&quot;);
      • keywords5.add(&quot;design&quot;);
      • keywords5.add(&quot;emotion&quot;);
      • keywords5.add(&quot;functionality&quot;);
      • keywords5.add(&quot;consumers&quot;);
      • addBook(&quot;Emotional Design&quot;, keywords5);
      • keywords.clear();
      • }
      • }
      • At this point, you've got a working program without any JAX-RPC code . That's the beauty of using an API like JAX-RPC compared to, other technique .
      • With JAX-RPC, you write a normal Java class, without server-side or Web service-specific calls, and apply the JAX-RPC later.
      • 11. Turn your class to RPC Service
        • making an RPC means to call a method on another machine somewhere.
        • In the case of the BookSearcher, we put the BookSearcher class on a Web server somewhere and run a program that uses that class on your local machine.
      • Right now, we have a class (BookSearcher) that will be on the server side of our RPC setup.
      • It's just an ordinary Java class now, but once we make certain methods available via RPC, our class is referred to as a service . It serves clients by providing them functions (methods) that can be called. The calling code is referred to as the client or caller .
      • 12. Copy your .java file to a .jws file
      • In the case of Axis, the easiest and fastest way to publish your service is to use JWS files. All you need to do is copy your Java source file (ending with .java) to a file with the same name but a .jws extension
      • 13. Copy .jws file into axis folder
      • C:Program FilesApache Software FoundationTomcat 6.0webappsaxis
      • As soon as the Axis Web application &quot;sees&quot; a .jws file in its directory, it compiles the file into a Java Web Service and builds all the SOAP access code needed to allow a client to access the class. Axis even deploys the service right away.
      • Start up your servlet engine. The Axis Web application is available at http:// hostname : port /axis .
        • http://localhost:8080/axis/BookSearcher.jws
    • Build a client to access a web-service
      • 13 . Update your classpath
      • Set enviroment variables of classpath
      • Earlier, you dropped several JAR files into your servlet engine's lib/directory and used the Axis validation JSP to ensure all those JARs were correctly located.
        • C:Program FilesApache Software FoundationTomcat 6.0lib mail.jar ;
        • C:Program FilesApache Software FoundationTomcat 6.0lib activation.jar ;
      • Add the JAX-RPC and Axis JARs
      • First, navigate back to your Axis installation and take a look at the lib directory. You should see something It's easiest to add all of these JAR files to your classpath
        • C:Program FilesApache Software FoundationTomcat 6.0webappsaxisWEB-INFlib axis.jar ;
        • C:.......................lib axis-ant.jar ;
        • C:.......................lib jaxrpc.jar ;
        • C:.......................lib saaj.jar ;
        • C:.......................lib wsdl4j-1.5.1.jar ;
        • C:.......................lib commons-logging-1.0.4.jar ;
        • C:.......................lib commons-discovery-0.2.jar ;
        • C:.......................lib log4j-1.2.8.jar ;
      • 14 . Create Client file BookSearcherClient.java
      • import java.io.IOException;
      • import java.net.MalformedURLException;
      • import java.net.URL;
      • import javax.xml.namespace.QName;
      • import javax.xml.rpc.ServiceException;
      • import org.apache.axis.client.Call;
      • import org.apache.axis.client.Service;
      • public class BookSearcherClient {
      • public static final String SERVICE_URL =&quot;http://localhost:8080/axis/BookSearcher.jws&quot;;
      • private Service service;
      • private Call call;
      • private URL serviceUrl;
      • public BookSearcherClient() { }
      • public Object[] search(String keyword) throws IOException
      • {
      • try {
      • if (service == null) {
      • service = new Service();
      • }
      • if (call == null) {
      • call = (Call)service.createCall();
      • }
      • if (serviceUrl == null)
      • {
      • serviceUrl = new URL(SERVICE_URL); //create a Java URL object to store the target endpoint — the Web-accessible
      • URL where your Web service is published:
      • }
      • call.setTargetEndpointAddress(serviceUrl); //At this point, our Call knows which service to connect to. However, we also need
      • to indicate the specific operation you want to invoke
      • call.setOperationName(new QName(&quot;http://soapinterop.org/&quot;,&quot;search&quot;)); //method for that, and you can't just pass in a simple string.Instead, you must pass that method a QName, indicate that we're working with SOAP encoding, and then provide the string name of the operation you want to call:
      • // Make call and get result
      • Object[] results = (Object[])call.invoke(new Object[] { keyword });
      • return results;
      • }
      • catch (MalformedURLException e) {
      • throw new IOException(&quot;Error creating service URL at &quot; + SERVICE_URL);
      • }
      • catch (ServiceException e) {
      • throw new IOException(&quot;Error creating service call: &quot; + e.getMessage());
      • } }
      • public static void main(String[] args) throws IOException {
      • if (args.length != 1) {
      • System.err.println(&quot;Usage: java BookSearcherClient [search keyword]&quot;);
      • return;
      • }
      • String keyword = args[0];
      • BookSearcherClient client = new BookSearcherClient();
      • Object[] results = client.search(keyword);
      • System.out.println(&quot;Returned books for keyword '&quot; + keyword + &quot;':&quot;);
      • for (int i = 0; i<results.length; i++) {
      • System.out.println(&quot; &quot; + results[i]);
      • }
      • } }
      • Compile and run :
        • Java BookSearcherClient business/presentation/design etc