WSDL2Java 与 Java2WSDL
时间:2006-04-05 来源:xianglinyan
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!
|
|