Create your webservice on BEA Weblogic, Part two

Ok, when I ended part one I had successfully generated serialization classes and type mappings with a little help from the autotype ant task. Now it´s time to generate the service components for my webservice. To do this I use a weblogic ant task called 'wsdl2Service'. As the name suggests it takes a .wsdl file as input an generates webservice components (interfaces, classes for user defined exceptions, en empty implementation class and a web-services.xml file). One limitation with this task is that it can only generate components for one service at a time. If you have more than one service defined in your .wsdl file you´ll have to run the task once for each service (this is documented). An undocumented 'feature' is the fact that the task only handle one 'port' entry for each service (afaik). Therefore I had to split my multiport service into several services with a one-to-one relationship between service and port.

The definition of the wsdl2Service task looks like this:
<taskdef name="wsdl2service" classname="weblogic.ant.taskdefs.webservices.wsdl2service.WSDL2Service" classpathref="classpath" />
The attributes I specify for this task is

  • wsdl - the same wsdl file as for the autotype task
  • serviceName - Since I have more than one service in my wsdl I need to specify which service to generate.
  • destDir - where to put the generated files
  • packageName - package for generated interface (and empty impl)
  • typeMappingFile - the types.xml file generated earlier by the autotype task
  • generateImpl - True, I will use this skeleton as delegate for my Session bean later on

The next step is to write your back-end component which will handle the webservice requests. You can implement your back-end component as a Stateless Session Beans, plain java classes or as a JMS consumer. The JMS way is not recommended though. I will use a Stateless Session Bean with xdoclet tags. In addition to the standard xdoclet tags I also use some Weblogic specific tags which can be found here.

The Session Bean is rather straight forward to write: I simply create a new class, tell it to implement the SessionBean interface as well as my webservice interface generated by the wsdl2Service task. Since I use xdoclet to generate home and business interfaces I need the @ejb.interface tag to tell xdoclet to inlcude my generated interface when generating the EJB interfaces. Hmm... a lot of interfaces here. Don´t forget to include the EJBObject and EJBLocalObject to the extends and the local-extends attribute of this tag. Pheew, with the EJB in place it´s time for lunch, to be continued.