Tuesday 22, Apr 2025
We are moved to new domain
Click -> www.ehowtonow.com
Saturday, 25 January 2014

JAX-WS wsgen tool

In this tutorial we are going to see how to generate web service client using wsgen tool.
The wsgen tool is used to generate required files from web service implementation class for web service deployment. The wsgen tool is built in tool available in JDK/bin folder
Two ways of using wsgen tool.
1. Generate java files (JAX-WS portable artifacts) for web service deployment
2. Generate WSDL and xsd files, for testing or web service client deployment
Refer this JAX-WS service example http://www.javatutorialcorner.com/2013/12/jax-ws-hello-world-web-service.html. create the web service and publish the web service
1. Generate java files (JAX-WS portable artifacts) for web service deployment
Use the following command to generate the JAX-WS artifacts from HelloWorldImpl.java class.
wsgen -verbose –keep -cp . {fully qualified class name }
Example:
C:\Documents and Settings\Administrator\jtc\WebService\bin>wsgen -verbose -keep
-cp . com.javatutorialscorner.jaxws.helloworld.HelloWorldImpl
Note:   ap round: 1
[ProcessedMethods Interface: com.javatutorialscorner.jaxws.helloworld.HelloWorld
]
[should process method: sayHello hasWebMethods: false ]
[endpointReferencesInterface: true]
[declaring class has WebSevice: true]
[returning: true]
[WrapperGen - method: sayHello(java.lang.String)]
[method.getDeclaringType(): com.javatutorialscorner.jaxws.helloworld.HelloWorld]
[requestWrapper: com.javatutorialscorner.jaxws.helloworld.jaxws.SayHello]
com\javatutorialscorner\jaxws\helloworld\jaxws\SayHello.java
com\javatutorialscorner\jaxws\helloworld\jaxws\SayHelloResponse.java
Note:   ap round: 2
[completing model for endpoint: com.javatutorialscorner.jaxws.helloworld.HelloWo
rldImpl]
[ProcessedMethods Interface: com.javatutorialscorner.jaxws.helloworld.HelloWorld
]
[should process method: sayHello hasWebMethods: false ]
[endpointReferencesInterface: true]
[declaring class has WebSevice: true]
[returning: true]
[WebServiceReferenceCollector - method: sayHello(java.lang.String)]
[completing model for endpoint: com.javatutorialscorner.jaxws.helloworld.HelloWo
rldImpl]
C:\Documents and Settings\Administrator\jtc\WebService\bin>

If you execute the followin command from command prompt C:\Documents and Settings\Administrator\jtc\WebService\bin>wsgen -verbose -keep
-cp . com.javatutorialscorner.jaxws.helloworld.HelloWorldImpl
you can see the above message for you artifacts generated successfully.
This command will generate four files.
com\javatutorialscorner\jaxws\helloworld\jaxws\SayHello.java
com\javatutorialscorner\jaxws\helloworld\jaxws\SayHello.class
com\javatutorialscorner\jaxws\helloworld\jaxws\SayHelloResponse.java
com\javatutorialscorner\jaxws\helloworld\jaxws\SayHelloResponse.class
SayHello.java
01.package com.javatutorialscorner.jaxws.helloworld.jaxws;
02. 
03.import javax.xml.bind.annotation.XmlAccessType;
04.import javax.xml.bind.annotation.XmlAccessorType;
05.import javax.xml.bind.annotation.XmlElement;
06.import javax.xml.bind.annotation.XmlRootElement;
07.import javax.xml.bind.annotation.XmlType;
08. 
09.@XmlRootElement(name = "sayHello", namespace = "http://helloworld.jaxws.javatutorialscorner.com/")
10.@XmlAccessorType(XmlAccessType.FIELD)
11.@XmlType(name = "sayHello", namespace = "http://helloworld.jaxws.javatutorialscorner.com/")
12.public class SayHello {
13. 
14.    @XmlElement(name = "arg0", namespace = "")
15.    private String arg0;
16. 
17.    /**
18.     *
19.     * @return
20.     *     returns String
21.     */
22.    public String getArg0() {
23.        return this.arg0;
24.    }
25. 
26.    /**
27.     *
28.     * @param arg0
29.     *     the value for the arg0 property
30.     */
31.    public void setArg0(String arg0) {
32.        this.arg0 = arg0;
33.    }
34. 
35.}

SayHelloResponse.java

01.package com.javatutorialscorner.jaxws.helloworld.jaxws;
02. 
03.import javax.xml.bind.annotation.XmlAccessType;
04.import javax.xml.bind.annotation.XmlAccessorType;
05.import javax.xml.bind.annotation.XmlElement;
06.import javax.xml.bind.annotation.XmlRootElement;
07.import javax.xml.bind.annotation.XmlType;
08. 
09.@XmlRootElement(name = "sayHelloResponse", namespace = "http://helloworld.jaxws.javatutorialscorner.com/")
10.@XmlAccessorType(XmlAccessType.FIELD)
11.@XmlType(name = "sayHelloResponse", namespace = "http://helloworld.jaxws.javatutorialscorner.com/")
12.public class SayHelloResponse {
13. 
14.    @XmlElement(name = "return", namespace = "")
15.    private String _return;
16. 
17.    /**
18.     *
19.     * @return
20.     *     returns String
21.     */
22.    public String get_return() {
23.        return this._return;
24.    }
25. 
26.    /**
27.     *
28.     * @param _return
29.     *     the value for the _return property
30.     */
31.    public void set_return(String _return) {
32.        this._return = _return;
33.    }
34. 
35.}


2. Generate WSDL and xsd files, for testing or web service client deployment

Use the following command to generate the WSDL and xsd files from HelloWorldImpl.java class.

C:\Documents and Settings\Administrator\jtc\WebService\bin>wsgen -verbose -keep
-cp . com.javatutorialscorner.jaxws.helloworld.HelloWorldImpl -wsdl
Note:   ap round: 1
[ProcessedMethods Interface: com.javatutorialscorner.jaxws.helloworld.HelloWorld
]
[should process method: sayHello hasWebMethods: false ]
[endpointReferencesInterface: true]
[declaring class has WebSevice: true]
[returning: true]
[WrapperGen - method: sayHello(java.lang.String)]
[method.getDeclaringType(): com.javatutorialscorner.jaxws.helloworld.HelloWorld]

[requestWrapper: com.javatutorialscorner.jaxws.helloworld.jaxws.SayHello]
com\javatutorialscorner\jaxws\helloworld\jaxws\SayHello.java
com\javatutorialscorner\jaxws\helloworld\jaxws\SayHelloResponse.java
Note:   ap round: 2
[completing model for endpoint: com.javatutorialscorner.jaxws.helloworld.HelloWo
rldImpl]
[ProcessedMethods Interface: com.javatutorialscorner.jaxws.helloworld.HelloWorld
]
[should process method: sayHello hasWebMethods: false ]
[endpointReferencesInterface: true]
[declaring class has WebSevice: true]
[returning: true]
[WebServiceReferenceCollector - method: sayHello(java.lang.String)]
[completing model for endpoint: com.javatutorialscorner.jaxws.helloworld.HelloWo
rldImpl]

If you execute the followin command from command prompt C:\Documents and Settings\Administrator\jtc\WebService\bin>wsgen -verbose -keep
-cp . com.javatutorialscorner.jaxws.helloworld.HelloWorldImpl -wsdl
you can see the above message for you artifacts generated successfully.

This command will generate four files.

com\javatutorialscorner\jaxws\helloworld\jaxws\SayHello.java

com\javatutorialscorner\jaxws\helloworld\jaxws\SayHello.class

com\javatutorialscorner\jaxws\helloworld\jaxws\SayHelloResponse.java

com\javatutorialscorner\jaxws\helloworld\jaxws\SayHelloResponse.class

HelloWorldImplService_schema1.xsd

HelloWorldImplService.wsdl


HelloWorldImplService_schema1.xsd

01.<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
03. 
04.  <xs:element name="sayHello" type="tns:sayHello"/>
05. 
06.  <xs:element name="sayHelloResponse" type="tns:sayHelloResponse"/>
07. 
08.  <xs:complexType name="sayHello">
09.    <xs:sequence>
10.      <xs:element name="arg0" type="xs:string" minOccurs="0"/>
11.    </xs:sequence>
12.  </xs:complexType>
13. 
14.  <xs:complexType name="sayHelloResponse">
15.    <xs:sequence>
16.      <xs:element name="return" type="xs:string" minOccurs="0"/>
17.    </xs:sequence>
18.  </xs:complexType>
19.</xs:schema>

HelloWorldImplService.wsdl

01.<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
03.  <types>
04.    <xsd:schema>
05.      <xsd:import namespace="http://helloworld.jaxws.javatutorialscorner.com/" schemaLocation="HelloWorldImplService_schema1.xsd"/>
06.    </xsd:schema>
07.  </types>
08.  <message name="sayHello">
09.    <part name="parameters" element="tns:sayHello"/>
10.  </message>
11.  <message name="sayHelloResponse">
12.    <part name="parameters" element="tns:sayHelloResponse"/>
13.  </message>
14.  <portType name="HelloWorld">
15.    <operation name="sayHello">
16.      <input message="tns:sayHello"/>
17.      <output message="tns:sayHelloResponse"/>
18.    </operation>
19.  </portType>
20.  <binding name="HelloWorldImplPortBinding" type="tns:HelloWorld">
21.    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
22.    <operation name="sayHello">
23.      <soap:operation soapAction=""/>
24.      <input>
25.        <soap:body use="literal"/>
26.      </input>
27.      <output>
28.        <soap:body use="literal"/>
29.      </output>
30.    </operation>
31.  </binding>
32.  <service name="HelloWorldImplService">
33.    <port name="HelloWorldImplPort" binding="tns:HelloWorldImplPortBinding">
34.      <soap:address location="REPLACE_WITH_ACTUAL_URL"/>
35.    </port>
36.  </service>
37.</definitions>

Shop and help us

Flipkart Offer Snapdeal offer Amazon.in offer Amazon.com offer

Related Posts:

  • JAX-WS wsgen tool In this tutorial we are going to see how to generate web service client using wsgen tool. The wsgen tool is used to generate required files from web service implementation class for web service deployment. The wsgen tool is … Read More
  • SOAP Web service Introduction In this tutorial we are going to see the introduction about SAOP web service. SOAP – Simple Object Access Protocol is standard protocol specification for message exchange based on XML.  Web service as two component … Read More
  • JAX-WS Hello World Web serviceIn this tutorial we are going to see how to create web service end point and client. Default its document style SOAP binding. Follow the steps given below to create hello world SOAP web service. 1. Open Eclipse, Select Fil… Read More
  • Axis2 – Message exchange patternIn this Tutorial we are going to see the quick overview of SOAP  message exchange patterns. Message Exchange PatternAll the SOAP messages carry the same structure, the ways in which they are used can be combined into a … Read More
  • JAX-WS wsimport tool In this tutorial we are going to see how to generate client using wsimport tool The wsimpot tool is used to generate generate web service client from WSDL file to access the published web service. you can see the wsimport to… Read More
  • Blogger Comments
  • Facebook Comments
  • Disqus Comments

0 comments:

Post a Comment

Item Reviewed: JAX-WS wsgen tool Rating: 5 Reviewed By: eHowToNow