我正在使用JDEV11.1.1.7.0。我是Webservices和SOAP的新手。我正在从现有的WSDL构建Web服务。
即。我创建了一个XSD和WSDL,然后在其上创建一个Web服务。我能够测试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分析器获取的响应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
有人可以告诉我,我在做什么错误?
我缺少哪些进口产品?
答案 0 :(得分: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>