Client Code

In the same way that we registered a new type mapping for the server code, we must now register a new type mapping within our client code. Unfortunately, this adds to the complexity of the client code, but remember that registering a new mapping is the same for server or client code. The only difference is that for server code, you can easily add new mappings via the simple web deployment tool, whereas the client code requires a more intimate knowledge of the SOAP API.

The complete client code is available in Example 5-5, shown later in this section. After setting the TargetObjectURI and method name, we set out to register a new type mapping.

First, we instantiate a new BeanSerializer object:

BeanSerializer bSerializer = new BeanSerializer(  );

This is the same class we used when deploying the server code. It is responsible for Java-to-XML serialization and XML-to-Java deserialization.

Second, we need to create a new SOAP mapping registry:

SOAPMappingRegistry registry = new SOAPMappingRegistry(  );

This creates a default registry object, which is already prepopulated with the mappings for strings, primitive data types, and arrays.

Third, we must create a Qualified Namespace object. This object must match the namespace URI and local part fields specified for the service deployment. In the case of our product parameter, the fields do indeed match up:

QName qname = new QName ("urn:examples", "product");

Fourth, we must register our new mapping for the ProductBean by calling ...

Get Web Services Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.