Tuesday, May 26, 2009

Creating a webservice using JAXWS - High Level Steps

1. Get the WSDL and XSD files of the webservice you need to implement.
Eg. For my webservice, I needed:
parlayx_terminal_location_notification_service_2_2.wsdl
parlayx_terminal_location_notification_interface_2_2.wsdl
parlayx_terminal_location_types_2_2.xsd
parlayx_common_types_2_1.xsd

2. Use WSIMPORT to generate the code stubs
Eg. command I used:
F:\EclipseWorkspaces\MANDPLBS\MAWS_Stubs>F:\Apache\jaxws-ri\bin\wsimport parlayx_terminal_location_notification_service_2_2.wsdl -keep -s src -d build\classes

I generated the source files in src and clases in build\classes so that I can use this directory as a project directory in Eclipse workspace

When you run it, you will see:
parsing WSDL...


generating code...


compiling code...

3. Amend the source files to implement your logic.
- Most of wsdl will generate an interface class
- You might want to implement that interface using a different class
- Eg. My interface class: TerminalLocationNotification
My implementation class TerminalLocationNotificationImpl
- If you change the package name, you will need to change the classname annotations

4. You can rename the classes but each object must be defined in ObjectFactory
Note: When I didn't comment out the classname wsgen (next step) created another package with jaxws

5. Generate the WSDL and artifacts using the following command:
>D:\Apache\jaxws-ri\bin\wsgen -cp ../build/classes -r ../WebContent/wsdl -s . -d ../build/classes -keep com..lbs.server.TerminalLocationNotificationImpl -wsdl

-r to generate WSDL to the right dir
-s to generate the source files to the right dir
-d to generate the class files to the right dir

6. Export as war and deploy on app server.

No comments:

Post a Comment