The article and the attached sample models included in the download section show how to use a WSDL-based web service in an application, and how to create a WSDL service from a model.
When using a web service, the best practice is to have the web service calls in a service provider model, then to implement the application user interface in a separate consumer model. This gives a benefit that you can easily test the web service functionality separate from your user interface. This sample illustrates that best practice.
This sample also illustrates two different approaches for implementing the web service calls. One way is to use the Web Service Call builder, which makes a single WSDL operation available. The second approach is only available as of Portlet Factory 6.1, and uses the Web Service Multi Operation builder. The Web Service Multi Operation builder can make all the operations in a WSDL available at once, and can automatically provide the functionality of Service Definition and Service Operation builders. The two approaches are shown in the OrdersProvider and OrdersProviderMultiOp models. If you compare those two models, you will see that the one using the Multi Operation builder contains many fewer builders.
The web service that's called in this sample comes from another model in this sample, the OrdersWSEnabledApplication model.
Here are some of the techniques illustrated in this sample:
- Creating a web service enabled application. This provides the WSDL service used by other models.
- Calling the web service from a provider model using the Web Service Call Builder, and making it available using the Service Definition and Service Operation builders.
- Calling the web service from a provider model using the Web Service Multi Operation Builder, which automatically includes the functionality of Service Definition and Service Operation.
- Consuming the service using a Service Consumer builder and building the user interface for the application using View & Form and other builders.
- OrdersWSEnabledApplication.model: This model acts as a web service enabled application for serving up sample XML data and performing operations on it to list, find, create, modify, and delete. Using the testing support enabled in this model you may run this model stand alone. You will find links to the various operations and a link to the generated wsdl.
- OrdersProvider.model: This model uses the Web Service Call builder to access the operations from a web service. This builder is used to call the web service defined in OrdersWSEnabledApplication.model. This model acts as a service provider using the operations defined in the Web Service Call builder.
- OrdersProviderMultiOp.model: This model uses the Web Service Multiple Operations builder to access the operations from a web service. This builder is used to call the web service defined in OrdersWSEnabledApplication.model. This model acts as a service provider using the operations defined in the Web Service Multi Operation builder.
- OrdersConsumer.model: This model acts as a service consumer to the OrdersProvider.model. This model provides the UI to expose the provider's functionality to a user.
- OrdersConsumerMultiOp.model - This model acts as a service consumer to the OrdersProviderMultiOp.model. This model provides the UI to expose the provider's functionality to a user.
Here is a screenshot of one of the consumer models (both consumer models have the same appearance when run):
Notes on running the sample and prerequisites
Portlet Factory 6.1.0 is required for the "MultiOp" sample models.
Import the attached zip file into your project using the Import WebSphere Portlet Factory Archive command. After reviewing the builders and builder inputs in all the models, try running the OrdersConsumer.model and the OrdersConsumerMultiOp.model.
The Web Service Call builder and the Web Service MultiOperation builder in the sample models have Logging set to All, so that the generated SOAP envelope will be saved to your deployed web application's WEB-INF/logs folder in debugTracing.txt.
Note, the producer or incoming web service portion of this sample is intended to be deployed in a standalone web application WAR, and not in a portlet WAR, as incoming web service producers are not supported in portlet WARs (you consume web services from portlets, as opposed to providing web services from portlets).