2011-01-09 26 views
2

我對Web服務非常陌生,我想知道如何將wsdl:type節中定義的類型保存到它自己的模式中,並且可以在多個WSDL中重用該模式。我一直在嘗試按照以下方式使用導入聲明,但這並不是非常成功。如何分離WSDL中的嵌入式模式?

 <wsdl:types> 
    <xsd:schema targetNamespace="http://ttdev.com/ss"> 
    <xsd:import namespace="http://ttdev.com/ss"schemaLocation="http://ttdev.com/ss/SimpleService.xsd"/> 
    </xsd:schema> 
</wsdl:types> 

<wsdl:definitions 
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://ttdev.com/ss" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="SimpleService" targetNamespace="http://ttdev.com/ss" xmlns:xi="http://www.w3.org/2001/XInclude"> 
<wsdl:types> 
<xsd:schema targetNamespace="http://ttdev.com/ss"> 
    <xsd:element name="concatRequest"> 
    <xsd:complexType> 
    <xsd:sequence> 
    <xsd:element name="param1" type="xsd:string"/> 
    <xsd:element name="param2" type="xsd:string"/> 
    </xsd:sequence> 
    </xsd:complexType> 
    </xsd:element> 
    <xsd:element name="concatResponse"> 
    <xsd:complexType> 
    <xsd:sequence minOccurs="0" maxOccurs="100"> 
    <xsd:element name="name" type="xsd:string"/> 
    <xsd:element name="description" type="xsd:string"/> 
    </xsd:sequence> 
    </xsd:complexType> 
    </xsd:element> 
    </xsd:schema> 
</wsdl:types> 
<wsdl:message name="concatRequest"> 
    <wsdl:part name="parameters" element="tns:concatRequest"/> 
</wsdl:message> 
<wsdl:message name="concatResponse"> 
    <wsdl:part name="parameters" element="tns:concatResponse"/> 
</wsdl:message> 
<wsdl:portType name="SimpleService"> 
    <wsdl:operation name="concat"> 
    <wsdl:input message="tns:concatRequest"/> 
    <wsdl:output message="tns:concatResponse"/> 
    </wsdl:operation> 
</wsdl:portType> 
<wsdl:binding name="SimpleServiceSOAP" type="tns:SimpleService"> 
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> 
    <wsdl:operation name="concat"> 
    <soap:operation soapAction="http://ttdev.com/ss/NewOperation"/> 
    <wsdl:input> 
    <soap:body use="literal"/> 
    </wsdl:input> 
    <wsdl:output> 
    <soap:body use="literal"/> 
    </wsdl:output> 
    </wsdl:operation> 
</wsdl:binding> 
<wsdl:service name="SimpleService"> 
    <wsdl:port name="p1" binding="tns:SimpleServiceSOAP"> 
    <soap:address location="http://localhost:8080/ss/p1"/> 
    </wsdl:port> 
</wsdl:service> 
</wsdl:definitions> 

總結:

  1. 我已經分離的模式到它自己的文件SinpleService.xsd(按照以下示例代碼)
  2. 我添加導入語句到WSDL按照上述。
  3. 但是,當我通過導入引用類型時,看起來類型無法解析。

<?xml version="1.0"?> 
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns1="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns2="http://ttdev.com/ss" targetNamespace="http://ttdev.com/ss"> 
<xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/" schemaLocation="http://schemas.xmlsoap.org/soap/encoding/"/> 
<xsd:import namespace="http://www.w3.org/2001/XMLSchema"/> 
<xsd:element name="concatRequest"> 
    <xsd:complexType> 
    <xsd:sequence> 
    <xsd:element name="param1" type="xsd:string"/> 
    <xsd:element name="param2" type="xsd:string"/> 
    </xsd:sequence> 
    </xsd:complexType> 
</xsd:element> 
<xsd:element name="concatResponse"> 
    <xsd:complexType> 
    <xsd:sequence minOccurs="0" maxOccurs="100"> 
    <xsd:element name="name" type="xsd:string"/> 
    <xsd:element name="description" type="xsd:string"/> 
    </xsd:sequence> 
    </xsd:complexType> 
</xsd:element> 
</xsd:schema> 
+0

`import`是正確的做法,堅持下去。告訴我們爲什麼它不起作用。 – skaffman 2011-01-09 22:00:02

+0

WSDL未通過驗證,這是我回來的錯誤: C:\ Users \ User \ workspace \ Axis2SimpleService \ src \ main \ resources \ SimpleService.wsdl無效。字符's'在語法上是意想不到的原因:預期下列之一'/>''>'詳細信息XML生產:生產'元素'不滿意 – user465374 2011-01-09 22:03:22

回答

2

試試這個:

SimpleServiceSchema.xsd:

<xsd:schema targetNamespace="http://ttdev.com/ss/include" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
    <xsd:complexType name="concatRequestType"> 
     <xsd:sequence> 
      <xsd:element name="param1" type="xsd:string"/> 
      <xsd:element name="param2" type="xsd:string"/> 
     </xsd:sequence> 
    </xsd:complexType> 
    <xsd:complexType name="concatResponseType"> 
     <xsd:sequence minOccurs="0" maxOccurs="100"> 
      <xsd:element name="name" type="xsd:string"/> 
      <xsd:element name="description" type="xsd:string"/> 
     </xsd:sequence> 
    </xsd:complexType> 
</xsd:schema> 


<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://ttdev.com/ss" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:inc="http://ttdev.com/ss/include" name="SimpleService" targetNamespace="http://ttdev.com/ss"> 
    <wsdl:types> 
     <xsd:schema targetNamespace="http://ttdev.com/ss"> 
      <xsd:import namespace="http://ttdev.com/ss/include" schemaLocation="SimpleServiceSchema.xsd"/> 
      <xsd:element name="concatRequest" type="inc:concatRequestType"/> 
      <xsd:element name="concatResponse" type="inc:concatResponseType"/> 
     </xsd:schema> 
    </wsdl:types> 
    <wsdl:message name="concatRequest"> 
     <wsdl:part name="parameters" element="tns:concatRequest"/> 
    </wsdl:message> 
    <wsdl:message name="concatResponse"> 
     <wsdl:part name="parameters" element="tns:concatResponse"/> 
    </wsdl:message> 
    <wsdl:portType name="SimpleService"> 
     <wsdl:operation name="concat"> 
      <wsdl:input message="tns:concatRequest"/> 
      <wsdl:output message="tns:concatResponse"/> 
     </wsdl:operation> 
    </wsdl:portType> 
    <wsdl:binding name="SimpleServiceSOAP" type="tns:SimpleService"> 
     <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> 
     <wsdl:operation name="concat"> 
      <soap:operation soapAction="http://ttdev.com/ss/NewOperation"/> 
      <wsdl:input> 
       <soap:body use="literal"/> 
      </wsdl:input> 
      <wsdl:output> 
       <soap:body use="literal"/> 
      </wsdl:output> 
     </wsdl:operation> 
    </wsdl:binding> 
    <wsdl:service name="SimpleService"> 
     <wsdl:port name="p1" binding="tns:SimpleServiceSOAP"> 
      <soap:address location="http://localhost:8080/ss/p1"/> 
     </wsdl:port> 
    </wsdl:service> 
</wsdl:definitions> 

(謝謝你,XMLSpy的)

0

您需要引號後的空間:

<xsd:import namespace="http://ttdev.com/ss"schemaLocation="http://ttdev.com/ss/SimpleService.xsd"/> 

應該

<xsd:import namespace="http://ttdev.com/ss" schemaLocation="http://ttdev.com/ss/SimpleService.xsd"/>