簡體   English   中英

此SOAP響應是否與WSDL / XSD一致?

[英]Is this SOAP response consistent with the WSDL/XSD?

我正在向(內部)肥皂服務發送請求。 我目前正在測試SUDS (Jurko的fork)和OSA python soap庫。 兩者都無法整理回應。

對成功請求的原始xml響應是:

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
  <S:Body>
    <ns2:geocodeAddressResponse xmlns:ns2="http://geocodegateway">
      <geocodedAddress>
        <streetLine>1 SOME STREET</streetLine>
        <suburb>SOMEBURB</suburb>
        <state>SS</state>
        <postcode>1234</postcode>
        <x>111.222222</x>
        <y>-22.333333</y>
      </geocodedAddress>       
etc...

OSA和SUDS庫都引發了異常:

  • OSA異常是ValueError: 'streetLine' is not in list
  • SUDS異常是TypeNotFound: Type not found: 'streetLine'

soap服務的XSD(由WSDL導入)是:

<?xml version="1.0" encoding="UTF-8"?><!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.7-b01-. --><xs:schema xmlns:gns="http://geocodegateway" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0" targetNamespace="http://geocodegateway">
  <xs:element name="address" nillable="true" type="gns:address"></xs:element>
  <xs:element name="geocodeAddressRequest" nillable="true" type="gns:geocodeAddressRequest"></xs:element>
  <xs:element name="geocodeAddressResponse" nillable="true" type="gns:geocodeAddressResponse"></xs:element>
  <xs:complexType name="address">
    <xs:sequence>
      <xs:element name="streetLine" type="xs:string"></xs:element>
      <xs:element name="suburb" type="xs:string"></xs:element>
      <xs:element name="state" type="xs:string"></xs:element>
      <xs:element name="postcode" type="xs:string"></xs:element>
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="geocodeAddressRequest">
    <xs:sequence>
      <xs:element name="appId" type="xs:string"></xs:element>
      <xs:element name="address" nillable="true" type="gns:address"></xs:element>
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="geocodeAddressResponse">
    <xs:sequence>
      <xs:element name="responseCode" type="xs:string" maxOccurs="1" minOccurs="1"></xs:element>
      <xs:element name="geocodedAddress">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="address" nillable="true" type="gns:address"></xs:element>
            <xs:element name="x" type="xs:string"></xs:element>
            <xs:element name="y" type="xs:string"></xs:element>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:sequence>
  </xs:complexType>
</xs:schema>

如果我通過SUDS MessagePlugin掛鈎修改響應XML以將streetLine,suburb等元素包裝在地址元素中,那么SUDS會正確地編組響應。

或者,如果我使用suds DocumentPlugin掛鈎(如下所示)修改XSD以刪除地址類型並包含單獨的streetLine,suburb等元素,那么SUDS會正確地編組響應。

<xs:complexType name="geocodeAddressResponse">
  <xs:sequence>
    <xs:element name="responseCode" type="xs:string" maxOccurs="1" minOccurs="1"/>
    <xs:element name="geocodedAddress">
      <xs:complexType>
        <xs:sequence>
          <xs:element name="streetLine" type="xs:string"></xs:element>
          <xs:element name="suburb" type="xs:string"></xs:element>
          <xs:element name="state" type="xs:string"></xs:element>
          <xs:element name="postcode" type="xs:string"></xs:element>
          <xs:element name="x" type="xs:string"></xs:element>
          <xs:element name="y" type="xs:string"></xs:element>
        </xs:sequence>
      </xs:complexType>
    </xs:element>
  </xs:sequence>
</xs:complexType>

我向soap服務的開發人員建議,可能應修改XSD或XML響應,使它們保持一致,但被告知它們似乎是正確的,並檢查我正在使用的python soap庫是否指定/解釋文檔/ literal vs document / literal正確包裝(我不知道這在哪里適用)。

問題 :SOAP響應是否與WSDL / XSD一致,而python soap庫是否正確解釋它(或者我沒有正確使用它們)?

原始XML響應不與WSDL內聯。

也許類型和元素之間存在混淆:

WSDL中捆綁的XSD的這一部分定義了一個名為“address”的類型

 <xs:complexType name="address">
    <xs:sequence>
        <xs:element name="streetLine" type="xs:string"></xs:element>
        <xs:element name="suburb" type="xs:string"></xs:element>
        <xs:element name="state" type="xs:string"></xs:element>
        <xs:element name="postcode" type="xs:string"></xs:element>
   </xs:sequence>
 </xs:complexType>

而同一XSD的這一部分定義了一個元素 ,該元素在geocodedAddress中也稱為“地址”,並且是上面定義的“地址” 類型

 <xs:element name="geocodedAddress">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="address" nillable="true" type="gns:address"></xs:element>

因此根據該定義,原始肥皂響應應如下所示:

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
  <S:Body>
    <ns2:geocodeAddressResponse xmlns:ns2="http://geocodegateway">
      <geocodedAddress>
        <address>
            <streetLine>1 SOME STREET</streetLine>
            <suburb>SOMEBURB</suburb>
            <state>SS</state>
            <postcode>1234</postcode>
            <x>111.222222</x>
            <y>-22.333333</y>
        </address>
      </geocodedAddress>  

而沒有單獨的gns:地址類型定義的geocodedAddress的等價物將是這樣的:

<xs:complexType name="geocodeAddressResponse">
  <xs:sequence>
    <xs:element name="responseCode" type="xs:string" maxOccurs="1" minOccurs="1"/>
    <xs:element name="geocodedAddress">
      <xs:complexType>
        <xs:sequence>
          <xs:element name="address">
            <xs:complexType>
              <xs:sequence>
                <xs:element name="streetLine" type="xs:string"></xs:element>
                <xs:element name="suburb" type="xs:string"></xs:element>
                <xs:element name="state" type="xs:string"></xs:element>
                <xs:element name="postcode" type="xs:string"></xs:element>
                <xs:element name="x" type="xs:string"></xs:element>
                <xs:element name="y" type="xs:string"></xs:element>
              </xs:sequence>
            </xs:complexType>
          </xs:element>
        </xs:sequence>
      </xs:complexType>
    </xs:element>
  </xs:sequence>
</xs:complexType>

你是對的,這不一致。

選項1

如果XSD看起來像這樣:

  <xs:element name="geocodedAddress">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="address" nillable="true" type="gns:address"></xs:element>
        <xs:element name="x" type="xs:string"></xs:element>
        <xs:element name="y" type="xs:string"></xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

XML應如下所示:

  <geocodedAddress>
     <address>
        <streetLine>Street 1</streetLine>
        <suburb>Suburb 1</suburb>
        <state>XX</state>
        <postcode>1234</postcode>
     </address>
     <x>111.11</x>
     <y>-22.22</y>
  </geocodedAddress>

選項2

如果XSD看起來像這樣:

<xs:element name="geocodedAddress">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="streetLine" type="xs:string"></xs:element>
      <xs:element name="suburb" type="xs:string"></xs:element>
      <xs:element name="state" type="xs:string"></xs:element>
      <xs:element name="postcode" type="xs:string"></xs:element>
      <xs:element name="x" type="xs:string"></xs:element>
      <xs:element name="y" type="xs:string"></xs:element>
    </xs:sequence>
  </xs:complexType>
</xs:element>

XML應如下所示:

  <geocodedAddress>
      <streetLine>Street 1</streetLine>
      <suburb>Suburb 1</suburb>
      <state>XX</state>
      <postcode>1234</postcode>
      <x>111.11</x>
      <y>-22.22</y>
  </geocodedAddress>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM