2016-09-26 90 views
5

我從供應商處收到以下WSDL。它後面的示例服務在Microsoft .NET上運行。我需要基於這個WSDL在Java中創建一個Web服務。Apache Axis:不包含元素

<?xml version="1.0" encoding="utf-8"?> 
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" 
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" 
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" 
xmlns:tns="http://www.somecompany.com/" 
xmlns:s="http://www.w3.org/2001/XMLSchema" 
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" 
targetNamespace="http://www.somecompany.com/" 
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"> 
    <wsdl:types> 
    <s:schema elementFormDefault="qualified" targetNamespace="http://www.somecompany.com/"> 
    <s:import namespace="http://www.w3.org/2001/XMLSchema" schemaLocation="http://www.w3.org/2001/XMLSchema.xsd" /> 
     <s:element name="getInventoryStatus"> 
     <s:complexType> 
      <s:sequence> 
      <s:element minOccurs="0" maxOccurs="1" name="DealerCode" type="s:string" /> 
      <s:element minOccurs="0" maxOccurs="1" name="SupplierCode" type="s:string" /> 
      <s:element minOccurs="0" maxOccurs="1" name="PartNumber" type="s:string" /> 
      <s:element minOccurs="1" maxOccurs="1" name="Quantity" type="s:int" /> 
      <s:element minOccurs="0" maxOccurs="1" name="DeliveryLocation" type="s:string" /> 
      </s:sequence> 
     </s:complexType> 
     </s:element> 
     <s:element name="getInventoryStatusResponse"> 
     <s:complexType> 
      <s:sequence> 
      <s:element minOccurs="0" maxOccurs="1" name="getInventoryStatusResult"> 
       <s:complexType> 
       <s:sequence> 
        <s:element ref="s:schema" /> 
        <s:any /> 
       </s:sequence> 
       </s:complexType> 
      </s:element> 
      </s:sequence> 
     </s:complexType> 
     </s:element> 
    </s:schema> 
    </wsdl:types> 
    <wsdl:message name="getInventoryStatusSoapIn"> 
    <wsdl:part name="parameters" element="tns:getInventoryStatus" /> 
    </wsdl:message> 
    <wsdl:message name="getInventoryStatusSoapOut"> 
    <wsdl:part name="parameters" element="tns:getInventoryStatusResponse" /> 
    </wsdl:message> 
    <wsdl:portType name="InventoryInquirySoap"> 
    <wsdl:operation name="getInventoryStatus"> 
     <wsdl:input message="tns:getInventoryStatusSoapIn" /> 
     <wsdl:output message="tns:getInventoryStatusSoapOut" /> 
    </wsdl:operation> 
    </wsdl:portType> 
    <wsdl:binding name="InventoryInquirySoap" type="tns:InventoryInquirySoap"> 
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" /> 
    <wsdl:operation name="getInventoryStatus"> 
     <soap:operation soapAction="http://www.somecompany.com/getInventoryStatus" style="document" /> 
     <wsdl:input> 
     <soap:body use="literal" /> 
     </wsdl:input> 
     <wsdl:output> 
     <soap:body use="literal" /> 
     </wsdl:output> 
    </wsdl:operation> 
    </wsdl:binding> 
    <wsdl:service name="InventoryInquiry"> 
    <wsdl:port name="InventoryInquirySoap" binding="tns:InventoryInquirySoap"> 
     <soap:address location="http://www.somecompany.com/InventoryInquiry.asmx" /> 
    </wsdl:port> 
    </wsdl:service> 
</wsdl:definitions> 

我修改我收到包含以下行的WSDL,這樣的Eclipse會識別爲有效的WSDL:

<s:import namespace="http://www.w3.org/2001/XMLSchema" schemaLocation="http://www.w3.org/2001/XMLSchema.xsd" /> <!-- added for Eclipse--> 

我已經包括在一個新的動態Web項目這個WSDL文件。我使用New Web Service嚮導來創建一個基於WSDL的新的自頂向下Web服務。

當我將項目部署到Tomcat和調用Web服務,Apache Axis的報告回如下:

軸誤差

抱歉,似乎已經錯了...這裏是細節:

故障 - makeTypeElement()被告知以創建類型 「{} http://www.somecompany.com/ >> getInventoryStatusResponse> getInventoryStatusResult」, 沒有含有元素

AxisFault的faultcode: {http://schemas.xmlsoap.org/soap/envelope/} Server.generalException faultSubcode:faultString:makeTypeElement()被告知以創建 型 「{} http://www.somecompany.com/ >> getInventoryStatusResponse> getInventoryStatusResult」, 沒有含有元素faultActor:faultNode:faultDetail : {} http://xml.apache.org/axis/主機名:HOME-DELL

由供應商提供的演示Web服務返回如下:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
    <soap:Body> 
     <GetInventoryStatusResponse xmlns="http://ctire.aktion.com/"> 
     <GetInventoryStatusResult> 
      <xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> 
       <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true"> 
        <xs:complexType> 
        <xs:choice minOccurs="0" maxOccurs="unbounded"> 
         <xs:element name="InventoryStatus"> 
          <xs:complexType> 
           <xs:sequence> 
           <xs:element name="InStock" type="xs:int" minOccurs="0"/> 
           <xs:element name="EstDeliveryDate" type="xs:string" minOccurs="0"/> 
           <xs:element name="EstDeliveryTime" type="xs:string" minOccurs="0"/> 
           <xs:element name="DeliveryLocation" type="xs:string" minOccurs="0"/> 
           </xs:sequence> 
          </xs:complexType> 
         </xs:element> 
        </xs:choice> 
        </xs:complexType> 
       </xs:element> 
      </xs:schema> 
      <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"> 
       <NewDataSet xmlns=""> 
        <InventoryStatus diffgr:id="InventoryStatus1" msdata:rowOrder="0" diffgr:hasChanges="inserted"> 
        <InStock>36</InStock> 
        <EstDeliveryDate>09/27/2016</EstDeliveryDate> 
        <EstDeliveryTime>12:00 PM</EstDeliveryTime> 
        <DeliveryLocation>883620750</DeliveryLocation> 
        </InventoryStatus> 
       </NewDataSet> 
      </diffgr:diffgram> 
     </GetInventoryStatusResult> 
     </GetInventoryStatusResponse> 
    </soap:Body> 
</soap:Envelope> 

我想我需要在WSDL中引用NewDataSet的模式,但我不知道該怎麼做。

回答

0

你知道嗎soapUI?您可以導入您的WSDL並針對演示服務發出一些請求。只是要檢查您的基礎設施是否正常工作。

如果一切似乎工作,試試這個: 具備Java通過 「wsimport的」 命令從WSDL中生成的類是這樣的:

%JAVA_HOME%/ bin中/ wsimport的-d [RELATIVE_PATH_FOR_GENERATED_CLASSES] - 編碼UTF-8 -keep -verbose [RELATIVE_PATH_OF_YOUR_WSDL]

在您的代碼中嘗試使用這些生成的類並再次部署。

您可以從here

希望幫助以任何方式獲得的wsimport的完整文檔。

+0

什麼的wsimport之間的區別並使用包括Axis在內的Axis用Eclipse編輯? –

+0

是的,我知道soapUI。正如問題所指出的那樣,問題是我無法訪問Axis構建的服務,這是由於將WSDL轉換爲Java類時出現的問題。 –

+0

您是否試圖通過wsimport生成工件?這個工具不止一次地爲我服務。其他工具的結果 - 我不記得我嘗試過了,但我認爲AXIS就是其中之一 - 沒有工作。 – actc

0

建議使用JAX-WS,這是一個Java標準。它與JAXB輕鬆合作,這在這裏也是需要的。

在這種情況下,服務器有一個動態響應,其中包含一個模式定義和一個空閒對象,但似乎是diffgram節點(來自Microsoft XSD)和符合以前的XSD定義的對象實例,一些diffgram屬性。因爲我沒有來自Microsoft的適當的XSD(它應該在「Visual Studio%InstallRoot%\ Xml \ Schemas目錄中的msdata.xsd」),所以此解決方案忽略diffgram節點(但不是它的內容)。這只是把正確的XSD並按照步驟的問題

步驟來創建服務:

  • 下載http://www.apache.org/dyn/closer.lua/cxf/2.7.18/apache-cxf-2.7.18.zip
  • 在Eclipse - >窗口 - >首選項 - > CXF - >添加和然後選擇+應用
  • 創建動態Web項目,並把WSDL在SRC
  • Web服務 - >生成Java框架 - >運行CXF - >完成
  • 的模式定義將在的DiffGram-v1.xsd樣本響應

  • 產生在一個命令行JAXB類與 「XJC的DiffGram-v1.xsd」(從Java類路徑倉)

  • 變化GetInventoryStatusResponse.GetInventoryStatusResult類定義之前加入「@XmlSeeAlso({NewDataSet的.class})」,以支持經由JABX在服務返回該對象
  • 實施InventoryInquirySoapImpl.getInventoryStatus返回XSD解析和NewDataSet的一個實例:

    InventoryStatus ie = new InventoryStatus(); 
        ie.setDeliveryLocation("del"); 
        ie.setInStock(36); 
        ie.setEstDeliveryDate("09/27/2016"); 
        ie.setDeliveryLocation("883620750"); 
    
        NewDataSet nds = new NewDataSet(); 
        nds.getInventoryStatus().add(ie); 
    
        GetInventoryStatusResponse.GetInventoryStatusResult _return = new GetInventoryStatusResponse.GetInventoryStatusResult(); 
    
        _return.setSchema(parseDiffgramSchema()); 
        _return.setAny(nds); 
        return _return; 
    
  • parseDiffgramSchema可以JABX實現:

    // TODO cache 
    URL file = this.getClass().getClassLoader() 
         .getResource("diffgram-v1.xsd"); 
    
    JAXBContext jaxbContext = JAXBContext.newInstance(Schema.class); 
    
    Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); 
    
    Schema schema = (Schema) jaxbUnmarshaller.unmarshal(file); 
    
    return schema; 
    

全部例如在我的GIT https://github.com/sergio-otero/TestJAXWS/tree/master/TestJAXWS

+0

我正在使用Axis從WSDL創建Web服務,而不是創建調用現有服務的客戶端。 –

+0

好的。我有一個返回「xs:schema」部分但不包含「diffgram」部分的例子。如果您可以從Visual Studio%InstallRoot%\ Xml \ Schemas目錄提供msdata.xsd,我會更容易 –

+0

實際的.NET Web服務來自供應商。我已經問過他們那個模式。 –