2016-09-26 86 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服务来自供应商。我已经问过他们那个模式。 –