1

WSDL で定義されたスキーマに対して SOAP リクエストを検証しようとしています。SOAP-Handler-Chain で SOAPHandler を使用しています。唯一の問題は、リクエストを検証しているときに次のエラーメッセージが表示されることです。

cvc-complex-type.2.4.a: Invalid content was found starting with element 'v1:latitude'. One of '{"http://schemas.domain.com/wsdl/fuelprice/v1/model":latitude}' is expected.

WSDL は次のようになります。

<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
      xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
      mlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
      mlns:http="http://schemas.xmlsoap.org/wsdl/http/"
      xmlns:xs="http://www.w3.org/2001/XMLSchema"
      xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
      xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:tns="http://schemas.domain.com/wsdl/fuelprice/v1"
      xmlns:model="http://schemas.domain.com/wsdl/fuelprice/v1/model"
      xmlns:exception="http://schemas.domain.com/wsdl/fuelprice/v1/exception"
      targetNamespace="http://schemas.domain.com/wsdl/fuelprice/v1">
<wsdl:types>
    <xsi:schema xmlns:xsi="http://www.w3.org/2001/XMLSchema" targetNamespace="http://schemas.domain.com/wsdl/fuelprice/v1" elementFormDefault="qualified">
        <xsi:import namespace="http://schemas.domain.com/wsdl/fuelprice/v1/model" schemaLocation="common.xsd"/>
        <xsi:import namespace="http://schemas.domain.com/wsdl/fuelprice/v1/exception" schemaLocation="exception.xsd"/>
        <xsi:import namespace="http://schemas.xmlsoap.org/soap/envelope/" schemaLocation="http://schemas.xmlsoap.org/soap/envelope/"/>
        <xsi:element name="GetAreaFuelStationsRequest">
            <xsi:complexType>
                <xsi:sequence>
                    <xsi:element name="area" type="model:Area"/>
                </xsi:sequence>
                <xsi:attribute name="provider" type="xsi:string" use="optional"/>
                <xsi:attribute name="prices" type="xsi:boolean" use="required"/>
            </xsi:complexType>
        </xsi:element>

XSD:

<?xml version="1.0" encoding="UTF-8"?>
<xsi:schema xmlns:xsi="http://www.w3.org/2001/XMLSchema" xmlns:model="http://schemas.domain.com/wsdl/fuelprice/v1/model" targetNamespace="http://schemas.domain.com/wsdl/fuelprice/v1/model" elementFormDefault="qualified">
<xsi:complexType name="FuelStation">
    <xsi:complexType name="Area">
        <xsi:sequence>
            <xsi:element name="center" type="model:GeoLocation"/>
            <xsi:element name="radius" type="xsi:float"/>
        </xsi:sequence>
    </xsi:complexType>
    <xsi:complexType name="GeoLocation">
        <xsi:sequence>
            <xsi:element name="latitude" type="xsi:double"/>
            <xsi:element name="longitude" type="xsi:double"/>
        </xsi:sequence>
        <xsi:attribute name="ellipsoid" type="xsi:string" use="required"/>
    </xsi:complexType>

ソース コード フラグメント:

    try {
        context.getMessage().getSOAPPart().getEnvelope();
        schemas = getSchemas(new URL(wsdlURI.toString().concat(wsdl)));
        schema = factory.newSchema(schemas);
        validator = schema.newValidator();
        validator.validate(new DOMSource(xml));
    }

リクエスト:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="http://schemas.domain.com/wsdl/fuelprice/v1" xmlns:mod="http://schemas.domain.com/wsdl/fuelprice/v1/model">
   <soapenv:Header/>
   <soapenv:Body>
      <v1:GetAreaFuelStationsRequest provider="ep1" prices="true">
         <v1:area>
            <mod:center ellipsoid="false">
                 <v1:latitude>49.8385</v1:latitude>
                 <v1:longitude>8.5014</v1:longitude>
            </mod:center>
            <mod:radius>10</mod:radius>
         </v1:area>
      </v1:GetAreaFuelStationsRequest>
   </soapenv:Body>
</soapenv:Envelope>

ここで何が悪いのか誰にもわかりますか?設定しました

elementFormDefault="qualified"

しかし、うまくいきませんでした。

4

2 に答える 2

2

エラー メッセージには重要な手がかりがあります。

cvc-complex-type.2.4.a: 要素「v1:latitude」で始まる無効なコンテンツが見つかりました。「{" http://schemas.domain.com/wsdl/fuelprice/v1/model ":latitude}」のいずれかが必要です。

XSDtargetNamespace

targetNamespace="http://schemas.domain.com/wsdl/fuelprice/v1/model"

名前空間プレフィックスの宣言に同意しません。

xmlns:v1="http://schemas.domain.com/wsdl/fuelprice/v1"

latitudeリクエストで使用:

 <v1:latitude>49.8385</v1:latitude>

それらを一致させて、エラーを排除します。

于 2014-12-16T20:07:17.573 に答える
0

それを機能させるために私がしたこと:

  1. SOAP/エンベロープ スキーマを wsdl にインポートしました
  2. request body 要素を取得し、そこからドキュメント ルートとしてドキュメントを作成しました
  3. body 要素に soap/envelope 名前空間を追加しました
于 2014-12-17T18:30:01.100 に答える