Dennis -- I think you misunderstood me. I'm not suggesting that you should
design your web services interfaces around the limitations of the current
platform. I'm suggesting that you design your interfaces based on the XML
Schema type system. I'm also not saying that XML Schema doesn't have the
ability to describe key/value pairs. I'm saying that XML Schema doesn't
define a standard collection type comparable to hashmap. In order to pass a
key/value pair, you need to define an XML Schema structure that can convey
the key/value pair information. And that structure should be defined as an
array.

It's actually pretty hard to describe your first XML representation of the
map instance in XML Schema:

  <map>
    <key>321</key>
    <value>Adam</value>
    <key>492</key>
    <value>Becky</value>
   <map>

You don't have an array in here, so you really can't represent the repeating
structure information, unless you want to use <xsd:any> in the definition. 

It's a much better idea to define the structure as an array:

<element name="map">
  <complexType>
    <sequence>
      <element name="item" type="tns:item" 
          minOccurs="0" maxOccurs="unbounded"/>
    </sequence>
  </complexType>
</element>
<complexType name="item">
  <sequence>
    <element name="key" type="string"/>
    <element name="value" type="string"/>
  </sequence>
</complexType>

But this schema would produce a document structure like this:

 <map>
  <item>
    <key>321</key>
    <value>Adam</value>
  </item>
  <item>
    <key>492</key>
    <value>Becky</value>
  </item>
 <map>

Now it's up to your serialization framework to map the array to a Java
collection.

I reiterate -- as a developer, your should define your SOAP interface based
on the XML structures you wish to exchange, not based on your Java service
object model.

Anne

-----Original Message-----
From: Dennis Sosnoski [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, November 02, 2004 3:34 AM
To: [EMAIL PROTECTED]
Subject: Re: Maximum Interoperability with "Map" objects

Anne, I think you're conflating the programming model and the data model 
here. I know you're doing it in the interest of keeping things simple, 
but I'm not sure that's a good idea in this case.

XML Schema can describe many representations of hashmaps, such as:

  <map>
    <key>321</key>
    <value>Adam</value>
    <key>492</key>
    <value>Becky</value>
   <map>
or

  <map>
    <item 
key="321"><person><first-name>Adam</first-name><last-name>Smith</last-name><
address>...</person></item>
    <item 
key="492"><person><first-name>Becky</first-name>...</person></item>
  </map>

There's just no one representation that's standard for hashmaps across 
languages and SOAP platforms. But the whole point of the move to doc/lit 
is that people need to describe the data they want to exchange in their 
web services, not the actual program implementations used for handling 
that data. If you've got a need to use data in the form of key-value 
pairs in your web service go ahead and do so, but recognize that 
depending on the framework you use you may need to go through some 
translation to take this to and from your application data structures. 
In the case of Axis this can mean converting to and from an array of 
JavaBeans for the actual data, or using a custom 
serializer/deserializer, or using data binding in combination with Axis. 
I don't think it's good to design your web services interfaces around 
the limitations of the current platform, though (especially since the 
platforms are all becoming more capable as time goes by).

  - Dennis

Anne Thomas Manes wrote:

>Mark,
>
>Designing a WSDL contract refers to the process of designing your SOAP
>interface based on the XML messages you intend to exchange (defined using
>XML Schema) rather than based on the Java interface of your service agent. 
>
>The XML Schema type system doesn't support Hashtables, Maps, Lists, etc,
>therefore your service should not expect to exchange these types. 
>
>You should define your XML message interface using simple types, structures
>of simple types, and arrays of simple types and structures of simple types.
>Structures may contain nested structures. In Java, these structures will
map
>to JavaBeans. They will map to comparable components in other languages.
>
>Anne
>
>-----Original Message-----
>From: Mark Chaimungkalanont [mailto:[EMAIL PROTECTED] 
>Sent: Sunday, October 31, 2004 5:44 PM
>To: [EMAIL PROTECTED]
>Subject: Re: Maximum Interoperability with "Map" objects
>
>I'm quite new to SOAP so I'm not entirely sure what "design WSDL 
>contract" actually entails. Are there any resources out there that you 
>would recommend? I've got a few google hits, but figure that people on 
>this list probably have their "favourite" resources. Is there a 
>collection of such resources somewhare?
>
>Cheers
>
>Mark C
>
>Egor Pervuninski wrote:
>
>  
>
>>Hello,
>>
>>## Mark Chaimungkalanont : Fri, 29 Oct 2004 17:07:25 +1000
>>
>>MC>  Hi there, I'm writing a SOAP service where interoperability is of
>>MC> utmost importance. I've read a few of the other posts on this, and
>>MC> people seem to be saying that Hashtables and the like are not
>>MC> interoperable. The best strategy seems to be writing a basic
>>MC> "Entry" bean with key value pairs, using the BeanSerializer and
>>MC> accepting an Array of them instead of a Map?
>>MC> 
>>MC> Is this the best way to attack the problem?
>>
>>To achieve maximum interoperability, it is better to design WSDL contract
>>and create program code from it.
>>
>>Regards,
>>Egor Pervuninski
>>[EMAIL PROTECTED]
>>

Reply via email to