2014-06-14 19 views
8

ho una richiesta SOAP: -Come risolvere soapenv: problema busta in schema XSD durante la convalida con richiesta SOAP/risposta

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="http://services.test.com/schema/MainData/V1"> 
    <soapenv:Header/> 
    <soapenv:Body> 
     <v1:retrieveDataRequest> 
     <v1:Id>58</v1:Id> 
     </v1:retrieveDataRequest> 
    </soapenv:Body> 
</soapenv:Envelope> 

e una risposta SOAP: -

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soap:Body> 
     <retrieveDataResponse xmlns="http://services.test.com/schema/MainData/V1"> 
     <Response>The Data retrieved from the Database</Response> 
     <Id>58</Id> 
     <Name>fdfdf</Name> 
     <Age>44</Age> 
     <Designation>sse</Designation> 
     </retrieveDataResponse> 
    </soap:Body> 
</soap:Envelope> 

Ora il mio XSD schema è: -

<?xml version="1.0" encoding="UTF-8"?> 
<schema xmlns="http://www.w3.org/2001/XMLSchema" 
targetNamespace="http://services.test.com/schema/MainData/V1" 
xmlns:tns="http://services.test.com/schema/MainData/V1" elementFormDefault="qualified"> 

    <complexType name="dataRequest"> 
     <sequence> 
      <element name="Id" type="int"></element> 
      <element name="Name" type="string"></element> 
      <element name="Age" type="int"></element> 
      <element name="Designation" type="string"></element> 
     </sequence> 
    </complexType> 

    <complexType name="dataResponse"> 
     <sequence> 
      <element name="Response" type="string"></element> 
      <element name="Id" type="int"></element> 
      <element name="Name" type="string"></element> 
      <element name="Age" type="int"></element> 
      <element name="Designation" type="string"></element> 
     </sequence> 
    </complexType> 

    <element name="insertDataRequest" type="tns:dataRequest"></element> 

    <element name="insertDataResponse" type="tns:dataResponse"></element> 


    <element name="retrieveDataRequest" type="tns:retrieveRequest"></element> 

    <element name="retrieveDataResponse" type="tns:dataResponse"></element> 

    <complexType name="retrieveRequest"> 
     <sequence> 
      <element name="Id" type="int"></element> 
     </sequence> 
    </complexType> 

    <element name="updateDataRequest" type="tns:dataRequest"></element> 

    <element name="updateDataRespone" type="tns:dataResponse"></element> 

    <complexType name="deleteRequest"> 
     <sequence> 
      <element name="ID" type="int"></element> 
     </sequence> 
    </complexType> 

    <element name="deleteDataRequest" type="tns:deleteRequest"></element> 

    <element name="deleteDataResponse" type="tns:dataResponse"></element> 
</schema> 

Ora il mio problema è ogni volta che provo per convalidare la mia richiesta SOAP contro questo schema XSD, ottengo il seguente errore: -

Not valid. 
Error - Line 1, 133: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 133; cvc-elt.1: Cannot find the declaration of element 'soapenv:Envelope'. 

Si prega di aiuto ... ho bisogno di sapere cosa devo modificare nel mio schema XSD in modo che la richiesta SOAP/risposta viene convalidare contro schema XSD ... Dato che io sono nuovo in questa e provato a cercare tutto su internet, non ho ottenuto risposta adeguata ... Si prega di aiutare

+0

Questa soluzione è fondamentalmente SOAP convalida XML contro XSD. non xml contro XSD. –

risposta

10

la richiesta e risposta SOAP non convalidare contro tua schema, ma lo schema SOAP. È possibile utilizzare il XSD per convalidare la richiesta e la risposta se importare SOAP XSD in esso:

<schema xmlns="http://www.w3.org/2001/XMLSchema" 
    targetNamespace="http://services.test.com/schema/MainData/V1" 
    xmlns:tns="http://services.test.com/schema/MainData/V1" elementFormDefault="qualified"> 

    <import namespace="http://schemas.xmlsoap.org/soap/envelope/" 
      schemaLocation="http://schemas.xmlsoap.org/soap/envelope/"></import> 

... 

Non devi farlo se il vostro esempio dichiara un attributo schemaLocation mappatura dei namespace di entrambi gli schemi (il tuo e lo schema SOAP) alle loro posizioni:

<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://services.test.com/schema/MainData/V1 your-schema.xsd 
         http://schemas.xmlsoap.org/soap/envelope/ http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soap:Body> 
     <retrieveDataResponse xmlns="http://services.test.com/schema/MainData/V1"> 
      <Response>The Data retrieved from the Database</Response> 
      <Id>58</Id> 
      <Name>fdfdf</Name> 
      <Age>44</Age> 
      <Designation>sse</Designation> 
     </retrieveDataResponse> 
    </soap:Body> 
</soap:Envelope> 
+0

La seconda opzione ottiene lo stesso risultato. Trasferisce semplicemente alle istanze la responsabilità di trovare gli schemi di sapone. Nel caso in cui non sia possibile modificare gli schemi (per aggiungere * import *), è possibile collegarli entrambi alle istanze utilizzando la seconda opzione e ancora convalidare i file. – helderdarocha

1

Ho avuto lo stesso problema e per me l'importazione dello schema non ha funzionato. Stack:

10:18:03,206 | DEBUG | iEsb | DefaultValidationErrorHandler | | 68 - org.apache.camel.camel-core - 2.6.0.fuse-03-01 | Validation error: org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'soapenv:Envelope'. 
org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'soapenv:Envelope'. 
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:233)[:] 

La mia versione Java è stato: 1.6.0_45. Ma ho risolto attraverso il download e l'importazione XSD come file:

<xsd:import namespace="http://schemas.xmlsoap.org/soap/envelope/" schemaLocation="envelope.xsd" /> 

Forse aiuterà qualcuno.

0

Quindi, la soluzione finale che ha funzionato per me sta usando importazione: -

<import namespace="http://schemas.xmlsoap.org/soap/envelope/" 
      schemaLocation="http://schemas.xmlsoap.org/soap/envelope/"></import> 
Problemi correlati