Apache Axis:不包含元素

时间:2016-09-26 11:35:56

标签: java apache web-services soap axis

我从供应商那里收到了以下WSDL。它背后的示例服务在Microsoft .NET上运行。我需要基于此WSDL在Java中创建Web服务。

<?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-->

我已将此WSDL文件包含在新的Dynamic Web Project中。我使用New Web Service向导基于WSDL创建了一个新的自上而下的Web服务。

当我将项目部署到Tomcat并调用Web服务时,Apache Axis会报告以下内容:

  

AXIS错误

     

抱歉,似乎出现了问题...以下是详细信息:

     

错误 - makeTypeElement()被告知要创建一个类型   “{http://www.somecompany.com/}&GT;&GT; getInventoryStatusResponse&GT; getInventoryStatusResult”,   没有包含元素

     

AxisFault faultCode:   {http://schemas.xmlsoap.org/soap/envelope/} Server.generalException   faultSubcode:faultString:makeTypeElement()被告知要创建一个   类型   “{http://www.somecompany.com/}&GT;&GT; getInventoryStatusResponse&GT; 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的模式,但我不知道该怎么做。

2 个答案:

答案 0 :(得分:0)

你知道soapUI吗?您可以导入W​​SDL并对演示服务发出一些请求。只是为了检查您的基础设施是否正常运行。

如果一切似乎都有效,请尝试以下方法: 让Java通过“wsimport”命令从WSDL生成类,如下所示:

  

%JAVA_HOME%/ bin / wsimport -d [RELATIVE_PATH_FOR_GENERATED_CLASSES] - 编码UTF-8 -keep -verbose [RELATIVE_PATH_OF_YOUR_WSDL]

在您的代码中尝试使用这些生成的类并再次部署。

您可以从here

获取wsimport的完整文档

希望以任何方式提供帮助。

答案 1 :(得分:0)

建议使用JAX-WS,这是一个Java标准。它与JAXB轻松合作,这也是必需的。

在这种情况下,服务器具有动态响应,其中包括模式定义和自由对象,但它似乎是一个diffgram节点(来自Microsoft XSD)和一个符合先前XSD定义的对象实例和一些diffgram attributes。

这个解决方案忽略了diffgram节点(但不是它的内容),因为我没有来自Microsoft的适当的XSD(它应该是来自Visual Studio%installRoot%\ Xml \ Schemas目录的msdata.xsd)。它是只需要放置正确的XSD并遵循这些步骤。

创建服务的步骤:

  • 下载http://www.apache.org/dyn/closer.lua/cxf/2.7.18/apache-cxf-2.7.18.zip
  • 在Eclipse中 - &gt;窗口 - &gt;偏好 - &gt; CXF - &gt;单击添加,然后选择+应用
  • 创建动态Web项目并将WSDL放在src
  • 网络服务 - &gt;生成Java Skeleton - &gt;运行时CXF - &gt;完成
  • 从diffgram-v1.xsd

    中的示例响应中输入模式定义

                                                                                                                                                                                                                                                                                                           

  • 使用“xjc diffgram-v1.xsd”(来自java bin classpath)在命令行中生成JAXB类

  • 在类定义“@XmlSeeAlso({NewDataSet.class})”之前添加GetInventoryStatusResponse.GetInventoryStatusResult,以支持在服务中通过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

中的完整示例