0

我正在使用 JDEV11.1.1.7.0。我是 Web 服务和 SOAP 的新手。我正在从现有的 WSDL 构建 Web 服务。

即,我创建了一个 XSD 和 WSDL,然后在其上创建了一个 Web 服务。我能够测试网络服务。我正在根据需要获得输出。但是,当我针对 XSD 验证 XML 时,它有一个错误。

XSD 是参考一个非常流行的博客 http://one-size-doesnt-fit-all.blogspot.in/2008/11/creating-jax-ws-web-services-via-wsdl.html准备的

从 HTTP Analyzer 获取的请求 XML:

<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" 
              xmlns:ns1="http://www.sagecomputing.com.au">  
   <env:Header/>  
   <env:Body>  
      <ns1:formInput>  
         <ns1:inputField1>1</ns1:inputField1>  
         <ns1:inputField2>Morning</ns1:inputField2>  
      </ns1:formInput>  
   </env:Body>  
</env:Envelope> 

从 HTTP Analyzer 获取的响应 XML:

<?xml version = '1.0' encoding = 'UTF-8'?>  
<S:Envelope xmlns:S="http://www.w3.org/2003/05/soap-envelope">  
   <S:Body>  
      <formOutput xmlns="http://www.sagecomputing.com.au">  
         <outputField1>6</outputField1>  
         <outputField2>Morning: Welcome!</outputField2>  
         <outputField3>This is your reply</outputField3>  
      </formOutput>  
   </S:Body>  
</S:Envelope>

XSD:

<?xml version="1.0" encoding="windows-1252" ?>  
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"  
  targetNamespace="http://www.sagecomputing.com.au"  
  elementFormDefault="qualified">  
  <xsd:element name="formInput">  
    <xsd:complexType>  
      <xsd:sequence>  
        <xsd:element name="inputField1" type="xsd:integer"/>  
      <xsd:element name="inputField2" type="xsd:string"/>  
      </xsd:sequence>  
    </xsd:complexType>  
  </xsd:element>  
  <xsd:element name="formOutput">  
    <xsd:complexType>  
      <xsd:sequence>  
        <xsd:element name="outputField1" type="xsd:integer"/>  
        <xsd:element name="outputField2" type="xsd:string"/>  
        <xsd:element name="outputField3" type="xsd:string"/>  
      </xsd:sequence>  
    </xsd:complexType>  
  </xsd:element>  
</xsd:schema>

当针对 XSD 验证 XML 时,我收到以下错误。

Cvc-elt.1: Cannot Find The Declaration Of Element 'S:Envelope'.. Line '1', Column '63'

我比较了使用免费在线 XML 验证器与 XSD 架构 - http://www.freeformatter.com/xml-validator-xsd.html

有人可以告诉我,我在做什么错吗?

有没有我遗漏的进口商品?

4

1 回答 1

0

尝试使用以下 xsd:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"  
targetNamespace="http://www.sagecomputing.com.au"  
elementFormDefault="qualified">  
<xsd:import namespace="http://schemas.xmlsoap.org/soap/envelope/" 
    schemaLocation="http://schemas.xmlsoap.org/soap/envelope/"/>
<xsd:element name="formInput">  
    <xsd:complexType>  
        <xsd:sequence>  
            <xsd:element name="inputField1" type="xsd:integer"/>  
            <xsd:element name="inputField2" type="xsd:string"/>  
        </xsd:sequence>  
    </xsd:complexType>  
</xsd:element>  
<xsd:element name="formOutput">  
    <xsd:complexType>  
        <xsd:sequence>  
            <xsd:element name="outputField1" type="xsd:integer"/>  
            <xsd:element name="outputField2" type="xsd:string"/>  
            <xsd:element name="outputField3" type="xsd:string"/>  
        </xsd:sequence>  
    </xsd:complexType>  
</xsd:element>  

更新:

根据上述 xsd 验证您的 SOAP 请求消息:

 <Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns1="http://www.sagecomputing.com.au"
        xsi:schemaLocation="http://www.sagecomputing.com.au soapMessage.xsd">
        <Header/>
        <Body>
            <ns1:formInput>  
                <ns1:inputField1>1</ns1:inputField1>  
                <ns1:inputField2>Morning</ns1:inputField2>  
            </ns1:formInput> 

        </Body>
    </Envelope>

根据上述 xsd 验证您的 SOAP 响应消息:

<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sagecomputing.com.au soapMessage.xsd">
<Header/>
<Body>
    <formOutput xmlns="http://www.sagecomputing.com.au">  
        <outputField1>6</outputField1>  
        <outputField2>Morning: Welcome!</outputField2>  
        <outputField3>This is your reply</outputField3>  
    </formOutput>  
</Body>
</Envelope>
于 2015-07-28T11:51:55.697 回答