【IT168 信息化】
清单 3: 地址查询 Web 服务的 WSDL 文件 -- <types> 元素 示例 1
<xsd:complexType name="
Address">
<xsd:sequence>
<xsd:element name="houseNumber" nillable="true" type="xsd:string" />
<xsd:element name="street" nillable="true" type="xsd:string" />
<xsd:element name="intersection" nillable="true" type="xsd:string" />
<xsd:element name="city" nillable="true" type="xsd:string" />
<xsd:element name="state_prov" nillable="true" type="xsd:string" />
<xsd:element name="zone" nillable="true" type="xsd:string" />
<xsd:element name="country" nillable="true" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="
AddressFinderOptions">
<xsd:sequence>
<xsd:element name="dataSource" nillable="true" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
现在,服务请求者能够知道如何来调用服务:一系列具有不同名字的字符串类型包括 Address 对象数据类型和一个描述 datasource 的字符串数据类型。 然而,WSDL 文件,或者说协议并 没有指明哪一个元素是调用服务必须的或可选的变量。 协议既没有说明调用服务有多少数据源,也没有说明有哪种数据源。服务请求者不得不检查 ArcWeb 服务的 Web 站点“关于数据源和信用”来了解 未包含在协议中的可获取数据源。尽管 <enumeration> 数据类型在 Web 服务开发中可以部分地解决数据源的选择问题,但对于服务请求者 WSDL 仍旧不是一个好的解决方案。
token 字符串数据类型是干什么的呢? token 作为输入变量是调用 findAddress 服务必须的。然而,您在地址查询 Web 服务的 WSDL 文件中能够找到的唯一线索就是作为 身份验证令牌的 <message> 元素中的 <documentation>元素。在检查和跟踪 ArcWeb 服务之后, 身份验证 是另一个 Web 服务 -- Authentication Web 服务验证服务请求者是否允许访问 ArcWeb 服务。 这意味这服务请求者必须与另外一个服务提供者签署协议来调用地址查询 Web 服务。
最终,在调用服务后,服务请求者所获得的输出是一个对象数据类型 -- LocationInfo。 为了找到一个给定地址的位置(经度和纬度),服务请求者必须跟踪如下所述的对象数据类型:
清单 4: 地址查询 Web 服务的 WSDL 文件 -- <types> 元素示例 2
<xsd:complexType name="
LocationInfo">
<xsd:sequence>
<xsd:element name="matchType" nillable="true" type="xsd:string" />
<xsd:element name="
candidates" nillable="true"
type=
"ns12:ArrayOfLocation" />
<xsd:element name="hasMore" type="xsd:boolean" />
<xsd:element name="errorCode" nillable="true" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
LocationInfo 中的一个元素是 ArrayOfLocation 数据类型,它包含如下所示的一个 location 数据类型数组。在示例中,只有 Morgantown 包含在输入变量中来调用地址查询 Web 服务,不同国家和地区关于 Morgantown 的 15 个位置将被作为输出变量返回,它们被包含在一个候选位置的数组中以供最终决策。
清单 5: 地址查询 Web 服务的 WSDL 文件 -- <types> 元素示例 3
<xsd:complexType name="
ArrayOfLocation">
<xsd:complexContent>
<xsd:restriction base="soapenc:Array">
<xsd:attribute ref="soapenc:arrayType" wsdl:arrayType=
"ns12:
Location[]" />
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
location 数据类型包含 point 数据类型来最终提供如下所示的位置信息(经度和纬度)。
Listing 6: 地址查询 Web 服务的 WSDL 文件 -- <types> 元素示例 4
<xsd:complexType name="Location">
<xsd:sequence>
<xsd:element name="point" nillable="true" type="ns11:
Point" />
<xsd:element name="description1" nillable="true" type="xsd:string" />
<xsd:element name="description2" nillable="true" type="xsd:string" />
<xsd:element name="score" type="xsd:double" />
<xsd:element name="matchType" nillable="true" type="xsd:string" />
<xsd:element name="type" nillable="true" type="xsd:string" />
<xsd:element name="locationExtent" nillable="true" type=
"ns11:Envelope" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="
Point">
<xsd:sequence>
<xsd:element name="
x" type="xsd:double" />
<xsd:element name="
y" type="xsd:double" />
<xsd:element name="coordinateSystem" nillable="true" type=
"ns11:CoordinateSystem" />
</xsd:sequence>
</xsd:complexType>