我从供应商那里收到了以下 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 文件包含在一个新的动态 Web 项目中。我使用新建 Web 服务向导创建了一个基于 WSDL 的自上而下的新 Web 服务。
当我将项目部署到 Tomcat 并调用 Web 服务时,Apache Axis 报告如下:
AXIS error
Sorry, something seems to have gone wrong... here are the details:
Fault - makeTypeElement() was told to create a type "{http://www.somecompany.com/}>>getInventoryStatusResponse>getInventoryStatusResult", with no containing element
AxisFault faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.generalException faultSubcode: faultString: makeTypeElement() was told to create a type "{http://www.somecompany.com/}>>getInventoryStatusResponse>getInventoryStatusResult", with no containing element faultActor: faultNode: faultDetail: {http://xml.apache.org/axis/}hostname: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 的模式,但我不确定该怎么做。
最佳答案
你知道吗soapUI ?您可以导入 WSDL 并对演示服务发出一些请求。只是为了检查您的基础设施是否正常工作。
如果一切正常,试试这个: 让 Java 通过“wsimport”命令从 WSDL 生成类,如下所示:
%JAVA_HOME%/bin/wsimport -d [RELATIVE_PATH_FOR_GENERATED_CLASSES] -encoding UTF-8 -keep -verbose [RELATIVE_PATH_OF_YOUR_WSDL]
在您的代码中尝试使用这些生成的类并再次部署。
您可以从 here 获得 wsimport 的完整文档
希望对您有所帮助。
关于java - Apache Axis : no containing element,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39701783/