2

WSDL に対して SOAP 応答メッセージを検証しようとしています。この質問に記載されているサンプルに従っています。ただし、以下の例外が発生します。

org.xml.sax.SAXParseException: src-resolve: Cannot resolve the name 'SOAP-ENC:Array' to a(n) 'type definition' component.

同様のエラーに関する質問を見たことがありますが、これが同じ問題かどうかはわかりません。また、 SOAP仕様SOAP-ENC:Arrayに表示されたときに、その質問で非標準と見なされる理由もわかりません。

これが私の検証コードです。例外はSchema schema = schemaFactory.newSchema(schemas)行で発生します。

DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document wsdlDoc = db.newDocument();
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
Source wsdlSource = new StreamSource(new File("d:\\temp\\demo.wsdl"));
transformer.transform(wsdlSource, new DOMResult(wsdlDoc));

NodeList schemaNodes = wsdlDoc.getElementsByTagNameNS(XMLConstants.W3C_XML_SCHEMA_NS_URI, "schema");
int nrSchemas = schemaNodes.getLength();

Source[] schemas = new Source[nrSchemas];
for (int i = 0; i < nrSchemas; ++i)
{
  schemas[i] = new DOMSource(schemaNodes.item(i));
}

SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = schemaFactory.newSchema(schemas);
Validator validator = schema.newValidator();
Source soapMessage = new StreamSource(new File("d:\\temp\\soapmessage.xml"));
Result result = new StreamResult(System.out);
validator.validate(soapMessage, result);

私は WSDL をトリミングし、関連する部分、または少なくとも関連すると思われる部分のみを残しました。さらに必要な場合は、質問を更新します。

<?xml version='1.0' encoding='UTF-8'?>
<definitions xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
             xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
             xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" 
             xmlns:tns="run:demo" 
             xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
             xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
             xmlns="http://schemas.xmlsoap.org/wsdl/" 
             targetNamespace="run:demo">
  <types>
    <xsd:schema targetNamespace="run:demo">
      <xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
      <xsd:import namespace="http://schemas.xmlsoap.org/wsdl/"/>
      <xsd:complexType name="itemsCT">
        <xsd:all>
          <xsd:element name="Name" type="xsd:string"/>
          <xsd:element name="Address" type="xsd:string"/>
        </xsd:all>
      </xsd:complexType>
      <xsd:complexType name="itemsArray">
        <xsd:complexContent>
          <xsd:restriction base="SOAP-ENC:Array">
            <xsd:attribute ref="SOAP-ENC:arrayType" 
                           wsdl:arrayType="tns:itemsCT[]"/>
          </xsd:restriction>
        </xsd:complexContent>
      </xsd:complexType>
    </xsd:schema>
  </types>
</definitions>
4

1 に答える 1

2

当面の問題は、呼び出されているスキーマバリデーターが名前空間http://schemas.xmlsoap.org/soap/encoding/のスキーマドキュメントをロードしていないことです。これは、汎用バリデーターであり、SOAP の知識が組み込まれていないためです。または、schemas.xmlsoap.org のサーバーからスキーマ ドキュメントを取得できなかったためです。

http://schemas.xmlsoap.org/soap/encoding/およびhttp://schemas.xmlsoap.org/wsdl/名前空間のスキーマのローカル コピーがある場合は、スキーマの場所の情報を 2 つの名前空間に追加してみてください。 xsd:import 要素をスキーマに追加します。ローカル コピーをお持ちでない場合は、schemas.xmlsoap.org から応答を得ることが今よりもうまくいくことを願っています。

于 2013-08-16T01:50:11.027 に答える