技术开发 频道

如何创建和使用Web服务

  5-3  多态accessor

  许多语言允许能够多态访问多种类型值的accessor,每种类型在运行时可用。一个多态accessor实例必须包含一个"xsi:type"属性描述实际值的类型。例如,一个名为"cost"类型值为"xsd:float"的多态accessor编码如下: 

<cost  xsi:type="xsd:float">29.95</cost>与之对比,类型值不变的accessor编码如下: 

<cost>29.95</cost> 

  5-4  compound  types复合类型

  SOAP定义了与下列常在程序语言中出现的结构性模式对应的类型: 

  结构:一个"struct"是一个复合值,它的成员值的唯一区别是accessor名称,任意两个accessor名称都不相同。
  数组:一个"array"是一个复合值,它的成员值的唯一区别是序数位置。

  SOAP也允许结构和数组之外的其它数据的序列化,例如Directed-Labeled-Graph  Data  Model之类的数据中,单个节点有许多不同的accssor,有些不止出现一次。SOAP序列化规则不要求底层的数据模型在accssor之间区分次序,但如果有这样的次序的话,这些accssor必须按照这个顺序编码。 

  5-4-1  复合值,结构和值引用

  复合值的成员编码为accessor元素。当accessor由名区分时(如结构),accessor名即作为元素名。名局部于类型的accessor有不受限的名,其它的accessor则有受限的名。下面的例子是类型为"Book"的结构: 

<e:book>
<author>Henry  Ford</author>
<preface>Prefatory  text</preface>
<intro>This  is  a  book.</intro>
</e:Book> 

  以下是描述上面结构的schema片断: 

<element  name="book">
<complexType>
<element  name="author"  type="xsd:string"/>
<element  name="preface"  type="xsd:string"/>
<element  name="intro"  type="xsd:string"/>
</complexType>
</e:Book> 

  以下是一个同时具有简单和复杂成员类型的例子。它显示两层引用。注意"author"accssor元素的"href"属性是对相应具有"id"属性的值的引用。"address"与之类似。 

<e:book>
<title>My  Life  and  Work</title>
<author  href="#Person-1"/>
</e:Book>
<e:Person  id="Person-1">
<name>Henry  Ford</name>
<address  href="#Address-2"/>
</e:Person>
<e:Address  id="Address-2">
<email>mailto:henryford@hotmail.com</email>
<web>http://www.henryford.com<;;/web>
</e:Address> 

  当"person"的值和"address"的值是multi-reference时,上面的形式是正确的。如果它们是single-reference,就必须用嵌入的形式,如下所示: 

<e:book>
<title>My  Life  and  Work</title>
<author>
<name>Henry  Ford</name>
<address>
<email>mailto:henryford@hotmail.com</email>
<web>http://www.henryford.com<;;/web>
</address>
</author>
</e:Book> 

  如果添加一个限制,任意两个人都不会有相同的地址,并且地址可以是街道或email地址,一本书可以有两个作者,编码如下: 

<e:book>
<title>My  Life  and  Work</title>
<firstauthor  href="#Person-1"/>
<secondauthor  href="#Person-2"/>
</e:Book>
<e:Person  id="Person-1">
<name>Henry  Ford</name>
<address  xsi:type="m:Electronic-address">
<email>mailto:henryford@hotmail.com</email>
<web>http://www.henryford.com<;;/web>
</address>
</e:Person>
<e:Person  id="Person-2">
<name>Samuel  Crowther</name>
<address  xsi:type="n:Street-address">
<street>Martin  Luther  King  Rd</street>
<city>Raleigh</city>
<state>North  Carolina</state>
</address>
</e:Person> 

  序列化可以包含对不在同一个资源的值的引用: 

<e:book>
<title>Paradise  Lost</title>
<firstauthor  href="http://www.dartmouth.edu/~milton/";/>
</e:Book> 

  以下是描述上面结构的schema片断: 

<element name="book" type="tns:book"/> <complexType name="Book"> <!-- Either the following group must occur or else the href attribute must appear, but not both. --> <sequence minOccurs="0" maxOccurs="1"> <element name="title" type="xsd:string"/> <element name="firstauthor" type="tns:Person"/> <element name="secondauthor" type="tns:Person"/> </sequence> <attribute name="href" type="uriReference"/> <attribute name="id" type="ID"/> <anyAttribute namespace="##other"/> </complexType> <element name="Person" base="tns:Person"/> <complexType name="Person"> <!-- Either the following group must occur or else the href attribute must appear, but not both. --> <sequence minOccurs="0" maxOccurs="1"> <element name="name" type="xsd:string"/> <element name="address" type="tns:Address"/> </sequence> <attribute name="href" type="uriReference"/> <attribute name="id" type="ID"/> <anyAttribute namespace="##other"/> </complexType> <element name="Address" base="tns:Address"/> <complexType name="Address"> <!-- Either the following group must occur or else the href attribute must appear, but not both. --> <sequence minOccurs="0" maxOccurs="1"> <element name="street" type="xsd:string"/> <element name="city" type="xsd:string"/> <element name="state" type="xsd:string"/> </sequence> <attribute name="href" type="uriReference"/> <attribute name="id" type="ID"/> <anyAttribute namespace="##other"/> </complexType>
0
相关文章