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:
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
SayHelloResponse.java
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.
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
HelloWorldImplService.wsdl
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
package com.javatutorialscorner.jaxws.helloworld.jaxws; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; @XmlRootElement(name = "sayHello", namespace = "http://helloworld.jaxws.javatutorialscorner.com/") @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "sayHello", namespace = "http://helloworld.jaxws.javatutorialscorner.com/") public class SayHello { @XmlElement(name = "arg0", namespace = "") private String arg0; /** * * @return * returns String */ public String getArg0() { return this.arg0; } /** * * @param arg0 * the value for the arg0 property */ public void setArg0(String arg0) { this.arg0 = arg0; } }
SayHelloResponse.java
package com.javatutorialscorner.jaxws.helloworld.jaxws; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; @XmlRootElement(name = "sayHelloResponse", namespace = "http://helloworld.jaxws.javatutorialscorner.com/") @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "sayHelloResponse", namespace = "http://helloworld.jaxws.javatutorialscorner.com/") public class SayHelloResponse { @XmlElement(name = "return", namespace = "") private String _return; /** * * @return * returns String */ public String get_return() { return this._return; } /** * * @param _return * the value for the _return property */ public void set_return(String _return) { this._return = _return; } }
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
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <xs:schema version="1.0" targetNamespace="http://helloworld.jaxws.javatutorialscorner.com/" xmlns:tns="http://helloworld.jaxws.javatutorialscorner.com/" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="sayHello" type="tns:sayHello"/> <xs:element name="sayHelloResponse" type="tns:sayHelloResponse"/> <xs:complexType name="sayHello"> <xs:sequence> <xs:element name="arg0" type="xs:string" minOccurs="0"/> </xs:sequence> </xs:complexType> <xs:complexType name="sayHelloResponse"> <xs:sequence> <xs:element name="return" type="xs:string" minOccurs="0"/> </xs:sequence> </xs:complexType> </xs:schema>
HelloWorldImplService.wsdl
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <definitions targetNamespace="http://helloworld.jaxws.javatutorialscorner.com/" name="HelloWorldImplService" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://helloworld.jaxws.javatutorialscorner.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"> <types> <xsd:schema> <xsd:import namespace="http://helloworld.jaxws.javatutorialscorner.com/" schemaLocation="HelloWorldImplService_schema1.xsd"/> </xsd:schema> </types> <message name="sayHello"> <part name="parameters" element="tns:sayHello"/> </message> <message name="sayHelloResponse"> <part name="parameters" element="tns:sayHelloResponse"/> </message> <portType name="HelloWorld"> <operation name="sayHello"> <input message="tns:sayHello"/> <output message="tns:sayHelloResponse"/> </operation> </portType> <binding name="HelloWorldImplPortBinding" type="tns:HelloWorld"> <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/> <operation name="sayHello"> <soap:operation soapAction=""/> <input> <soap:body use="literal"/> </input> <output> <soap:body use="literal"/> </output> </operation> </binding> <service name="HelloWorldImplService"> <port name="HelloWorldImplPort" binding="tns:HelloWorldImplPortBinding"> <soap:address location="REPLACE_WITH_ACTUAL_URL"/> </port> </service> </definitions>
0 comments:
Post a Comment