Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0

Here is an example of an interface to a service. Note that the interface is optional, you can expose a class as a service - we've just used an interface in this example as its good practice and makes the example easier to follow.

Wiki Markup
{snippet:id=example|lang=java|url=http://cvs.activesoap.codehaus.org/viewrep/~raw,r=HEAD/activesoap/activesoap/src/test/org/codehaus/activesoap/examples/snowboard/SnowboardService.java}

Here's the WSDL that this service matches. Note that we hope to provide an extension to XMLBeans to allow this service interface to be auto-generated at the same time you auto-generate the XMLBeans from a WSDL.

There's a method on this interface which accepts an XMLBeans type and represents a WSDL operation. We can have as many methods as we like all auto-published, the only requirement is that when using the XMLBeansRegistery, the parameter must be an XMLBeans type, so that when we register it we can auto-deduce the QName which matches the correct method on the service.

Then if we register an implementation of this interface with the XMLBeansRegistry we can automatically publish the service as both REST and SOAP endpoints...

Wiki Markup
{snippet:id=example|lang=java|url=http://cvs.activesoap.codehaus.org/viewrep/~raw,r=HEAD/activesoap/activesoap/src/test/org/codehaus/activesoap/examples/snowboard/SnowboardTest.java}

Exposing services over HTTP

The following example demonstrates how to make a service available over HTTP using the SOAP protocl (1.2 is the default)

Wiki Markup
{snippet:id=soapServer|lang=java|url=http://cvs.activesoap.codehaus.org/viewrep/~raw,r=HEAD/activesoap/activesoap/src/test/org/codehaus/activesoap/examples/snowboard/SnowboardTest.java}

Here is the same service exposed as a pure REST service

Wiki Markup
{snippet:id=restServer|lang=java|url=http://cvs.activesoap.codehaus.org/viewrep/~raw,r=HEAD/activesoap/activesoap/src/test/org/codehaus/activesoap/examples/snowboard/SnowboardTest.java}

Client interface

As well as implementing web services, its also useful to be able to invoke them easily in a document centric way.

The following example demonstates how to invoke a web service using an XMLBeans interface for a WSDL endpoint.

Wiki Markup
{snippet:id=soapClient|lang=java|url=http://cvs.activesoap.codehaus.org/viewrep/~raw,r=HEAD/activesoap/activesoap/src/test/org/codehaus/activesoap/examples/snowboard/SnowboardTest.java}

Here's the same thing again for a service exposed via pure REST

Wiki Markup
{snippet:id=restClient|lang=java|url=http://cvs.activesoap.codehaus.org/viewrep/~raw,r=HEAD/activesoap/activesoap/src/test/org/codehaus/activesoap/examples/snowboard/SnowboardTest.java}

Another alternative is to use the Dynamic client API.