2014-06-14 29 views
8

我有一個SOAP請求確認: -如何解決soapenv:信封問題XSD架構,同時用SOAP請求/響應

<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> 

和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> 

現在我的XSD模式是: -

<?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> 

現在我的問題是每當我嘗試驗證我的SOAP請求對這個XSD架構,我得到以下錯誤: -

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'. 

請幫助...我需要知道我應該在我的XSD架構修改,以使SOAP請求/響應被驗證XSD架構......因爲我在這個新的嘗試搜索所有在互聯網上,我沒有得到合適的答案......請幫助

+0

該解決方案基本上是針對XSD SOAP XML驗證。不是針對XSD的xml。 –

回答

10

的SOAP請求和響應不驗證對模式,但SOAP模式。您可以使用XSD來驗證你的請求和響應如果導入的SOAP XSD進去:

<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> 

... 

你不必這樣做,如果你實例聲明一個schemaLocation屬性映射的名稱空間兩種模式(您的和SOAP模式)到他們的位置:

<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

第二個選項達到相同的結果。它只是將實例轉換爲查找肥皂模式的責任。在無法更改模式(添加* import *)的情況下,可以使用第二個選項將它們兩個鏈接到您的實例,然後仍然驗證這些文件。 – helderdarocha

1

我有同樣的問題,對於我的架構導入不起作用。 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)[:] 

我的java版本是:1.6.0_45。 但我解決它通過下載XSD和導入它作爲一個文件:

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

也許這將幫助別人。

0

所以,這對我工作的最終解決方案是使用進口: -

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