Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java -> WSDL and WSDL -> Java

 
Chengwei Lee
Ranch Hand
Posts: 884
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I've read through abit of J2EE Web Services (JAX-RPC) & found that it only covers WSDL -> Java (correct & pardon me if I'm wrong).
I gather that it would be more efficient for me to do it the Java -> WSDL way since I'm better in coding Java than grounds up from WSDL (won't have to be proficient in WSDL). Does the JAX-RPC compiler works both ways?
Or I've to depends on the J2EE vendor to provide this functionality? Like the application server?
 
iyven koh
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Chapter 15 of Richard Monson-Haefel's book does cover the topic on Mapping Java to WSDL and XML. There are some tools developed by vendors that convert Java to WSDL too.
 
Chengwei Lee
Ranch Hand
Posts: 884
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by iyven koh:
Hi,
Chapter 15 of Richard Monson-Haefel's book does cover the topic on Mapping Java to WSDL and XML. There are some tools developed by vendors that convert Java to WSDL too.

I've read through chapter 15 and I can't seems to find what I want there. Its mainly more of showing the mapping from WSDL -> Java, although it should work the other way round.
What I'm looking for is actually more of the steps (using a tool) to take to perform Java -> WSDL. I'm quite sure no one will be doing manual mapping, so there should be some automated tools out there to do the job. Unfortunately, the book doesn't seem to mention any that I could try out?
 
iyven koh
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have found this tool from Axis project by Apache. For more information you can go to Axis User's guide
Java2WSDL: Building WSDL from Java
The Java2WSDL and WSDL2Java emitters make it easy to develop a new web service. The following sections describe the steps in building a web service from a Java interface.

Step 1: Provide a Java interface or class
Write and compile a Java interface (or class) that describes the web service interface. Here is an example interface that describes a web services that can be used to set/query the price of widgets (samples/userguide/example6/WidgetPrice.java):
package samples.userguide.example6;
/**
* Interface describing a web service to set and get Widget prices.
**/
public interface WidgetPrice {
public void setWidgetPrice(String widgetName, String price);
public String getWidgetPrice(String widgetName);
}
Note: If you compile your class with debug information, Java2WSDL will use the debug information to obtain the method parameter names.
Step 2: Create WSDL using Java2WSDL
Use the Java2WSDL tool to create a WSDL file from the interface above.
Here is an example invocation that produces the wsdl file (wp.wsdl) from the interface described in the previous section:
% java org.apache.axis.wsdl.Java2WSDL -o wp.wsdl
-l"http://localhost:8080/axis/services/WidgetPrice"
-n "urn:Example6" -p"samples.userguide.example6" "urn:Example6"
samples.userguide.example6.WidgetPrice
Where:
-o indicates the name of the output WSDL file
-l indicates thelocation of the service
-n is the target namespace of the WSDL file
-p indicates a mapping from the package to a namespace. There may be multiple mappings.
the class specified contains the interface of the webservice.
The output WSDL document will contain the appropriate WSDL types, messages, portType, bindings and service descriptions to support a SOAP rpc, encoding web service. If your specified interface methods reference other classes, the Java2WSDL tool will generate the appropriate xml types to represent the classes and any nested/inherited types. The tool supports JAX-RPC complex types (bean classes), extension classes, enumeration classes, arrays and Holder classes.
The Java2WSDL tool has many additional options which are detailed in the reference guide. There is an Ant Task to integrate this action with an Ant based build process.
Step 3: Create Bindings using WSDL2Java
Use the generated WSDL file to build the appropriate client/server bindings for the web service (see WSDL2Java):
% java org.apache.axis.wsdl.WSDL2Java -o . -d Session -s -S true
-Nurn:Example6 samples.userguide.example6 wp.wsdl
This will generate the following files:
WidgetPriceSoapBindingImpl.java : Java file containing the default server implementation of the WidgetPrice web service.
You will need to modify the *SoapBindingImpl file to add your implementation (see samples/userguide/example6/WidgetPriceSoapBindingImpl.java ).
WidgetPrice.java: New interface file that contains the appropriate java.rmi.Remote usages.
WidgetPriceService.java: Java file containing the client side service interface.
WidgetPriceServiceLocator.java: Java file containing the client side service implementation class.
WidgetPriceSoapBindingSkeleton.java: Server side skeleton.
WidgetPriceSoapBindingStub.java: Client side stub.
deploy.wsdd: Deployment descriptor
undeploy.wsdd: Undeployment descriptor
(data types): Java files will be produced for all of the other types and holders necessary for the web service. There are no additional files for the WidgetPrice web service.
Now you have all of the necessary files to build your client/server side code and deploy the web service
 
Chengwei Lee
Ranch Hand
Posts: 884
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!
So I suppose different application server vendors would have their own tools for the mapping then...
 
Richard Monson-Haefel
author
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right. Each vendor will have their own tools, but keep in mind that for J2EE 1.4 the mapping from Java to WSDL is also dependent on the webservices.xml and the JAX-RPC Mapping file which provide additional information needed to geneerate the binding and service elements of a WSDL document. The webservices.xml and JAX-RPC Mapping files are covered in chapters 22- 24 (Part VII) of the J2EE Web Services book.
 
iyven koh
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the advantages and disadvatages for both Java to WSDL and WSDL to Java? Anybody has an idea on this?
 
Lipman Li
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
by using Java->WSDL, WSDL knowledge is not mandatory, It's easy to make your web service compliant with WS-I BP, it's better approach for those who is expert on java coding but less knowledge of WSDL. the limitation of this approach is that it too Java , so that some WSDL feature is not used fully. just RMH pointed out, the Java->WSDL also need to prepare the mapping file and webservices.xml file.

WSDL->Java approach, developer shall have enough knowledge to construct the WSDL, and make sure to conform to WS-I BP.

any more?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic