users@jax-rpc.java.net

Re: DII with complex types?

From: Arun Gupta <arun.gupta_at_Sun.COM>
Date: Fri, 12 Apr 2002 10:43:19 -0700

  Hi Michael,

Consider the following WSDL (for String[]):

<complexType name="ArrayOfstring">
   <complexContent>
      <restriction base="soap-enc:Array">
          <attribute ref="soap-enc:arrayType" wsdl:arrayType="string[]" />
      </restriction>
  </complexContent>
</complexType>

Your DII client code needs to register the serializer for String[] in
the type mapping registry. You do it using the following steps:

1). Include the following import statements in your code:
import javax.xml.rpc.Service;
import javax.xml.rpc.namespace.QName;
import com.sun.xml.rpc.encoding.SimpleTypeSerializer;
import com.sun.xml.rpc.encoding.CombinedSerializer;
import com.sun.xml.rpc.encoding.simpletype.XSDStringEncoder;
import com.sun.xml.rpc.encoding.SimpleTypeArraySerializer;
import com.sun.xml.rpc.encoding.ReferenceableSerializerImpl;
import com.sun.xml.rpc.encoding.SingletonSerializerFactory;
import com.sun.xml.rpc.encoding.SingletonDeserializerFactory;
import javax.xml.rpc.encoding.SerializerFactory;
import javax.xml.rpc.encoding.DeserializerFactory;

2). Your client class should implement the following interfaces:

com.sun.xml.rpc.encoding.SerializerConstants
com.sun.xml.rpc.wsdl.document.schema.SchemaConstants

3). You need to register the serializers for String[]:

Service service = factory.createService(new QName("service-name"));
TypeMappingRegistry registry = service.getTypeMappingRegistry();
TypeMapping typeMapping =
registry.getTypeMapping(SOAPConstants.URI_ENCODING);
QName stringArrayTypeQname = new QName( "http://foo.bar/types" ,
"ArrayOfstring");
QName stringArrayElementQname = new QName("", "string");
CombinedSerializer stringSerializer = new
SimpleTypeSerializer(QNAME_TYPE_STRING, DONT_ENCODE_TYPE, NULLABLE,
SOAPConstants.URI_ENCODING, XSDStringEncoder.getInstance());
CombinedSerializer stringArraySerializer = new
SimpleTypeArraySerializer(QNAME_TYPE_INT, ENCODE_TYPE, NULLABLE,
SOAPConstants.URI_ENCODING, stringArrayElementQname, QNAME_TYPE_INT,
String.class, 1, null, (SimpleTypeSerializer)stringSerializer);
stringArraySerializer = new
ReferenceableSerializerImpl(SERIALIZE_AS_REF, stringArraySerializer);
SerializerFactory stringArraySerializerFactory = new
SingletonSerializerFactory(stringArraySerializer);
DeserializerFactory stringArrayDeserializerFactory = new
SingletonDeserializerFactory(stringArraySerializer);
typeMapping.register(String[].class, stringArrayTypeQname,
boxedByteArraySerializerFactory, boxedByteArrayDeserializerFactory);

4). Finally invoke the method on the port:

QName port = new QName(YOUR_PORT);
Call call = newCall(service, port);
call.setReturnType(stringArrayTypeQname);
call.setOperationName(new QName( "http://foo.bar/wsdl" , "getStringArray"));
String[] stringArray = (String[])call.invoke(new Object[0]);

You can repeat the same steps for any other complex type defined by your
WSDL.

Thanks for your interest in JAX-RPC.

Regards,
-Arun

YAWN,MICHAEL (HP-Cupertino,ex1) wrote:

>Hi,
>
>I've gotten an example of DII to work, following the tutorial almost
>exactly.
>Now, I want to call two methods that return array types. One is an
>array of Strings, the other an array of a complex data type defined in
>the WSDL.
>
>These data types are known in the WSDL -- is there some mechanism
>to make them visible to the DII Client so I can use them as return
>types?
>
>Thanks,
>Mike
>

--
=============================================
There is only one me, I must live myself!
There is only one today, I must live itself!
=============================================
http://members.tripod.com/~apgupta/index.html
=============================================