2014-06-14 17 views
8

Tôi có một yêu cầu SOAP: -Làm thế nào để sửa chữa soapenv: Vấn đề Envelope trong giản đồ XSD khi xác nhận với SOAP request/response

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

và một phản ứng 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> 

Bây giờ XSD của tôi giản đồ là: -

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

Vấn đề của tôi là bất cứ khi nào tôi xác thực yêu cầu SOAP đối với lược đồ XSD này, tôi nhận được lỗi sau: -

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

Xin vui lòng giúp ... Tôi cần phải biết những gì tôi nên sửa đổi trong sơ đồ XSD của tôi để yêu cầu SOAP/phản ứng được xác nhận dựa trên giản đồ XSD ... Kể từ khi tôi mới ở đây và cố gắng tìm kiếm tất cả qua internet, tôi đã không nhận được câu trả lời phù hợp ... Xin vui lòng giúp

+0

Giải pháp này về cơ bản là SOAP xác nhận XML dựa trên XSD. không xml với XSD. –

Trả lời

10

yêu cầu SOAP và phản ứng không xác nhận đối với schema của bạn, nhưng schema SOAP. Bạn có thể sử dụng XSD của bạn để xác nhận request và response của bạn nếu bạn nhập SOAP XSD vào nó:

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

... 

Bạn không cần phải làm điều đó nếu bạn dụ khai báo một thuộc tính schemaLocation lập bản đồ không gian tên của cả hai lược đồ (của bạn và lược đồ SOAP) đến vị trí của chúng:

<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

Tùy chọn thứ hai đạt được kết quả tương tự. Nó chỉ đơn giản là chuyển giao cho các trường hợp trách nhiệm cho việc tìm kiếm các lược đồ xà phòng. Trong trường hợp bạn không thể thay đổi lược đồ của mình (để thêm * import *), bạn có thể liên kết cả hai lược đồ đó với các cá thể của bạn bằng cách sử dụng tùy chọn thứ hai và vẫn xác nhận hợp lệ các tệp. – helderdarocha

1

Tôi đã gặp vấn đề tương tự và đối với việc nhập giản đồ không hoạt động. Ngăn xếp:

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)[:] 

Phiên bản java của tôi là: 1.6.0_45. Nhưng tôi giải quyết nó thông qua tải xsd và nhập khẩu nó dưới dạng tệp:

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

Có lẽ nó sẽ giúp ai đó.

0

Vì vậy, giải pháp cuối cùng mà làm việc đối với tôi là sử dụng nhập khẩu: -

<import namespace="http://schemas.xmlsoap.org/soap/envelope/" 
      schemaLocation="http://schemas.xmlsoap.org/soap/envelope/"></import> 
Các vấn đề liên quan