gpt4 book ai didi

java - 将 WSDL 文件写入现有 Web 服务

转载 作者:行者123 更新时间:2023-11-30 11:57:38 25 4
gpt4 key购买 nike

我需要将 WSDL 文件写入同事提供给我的现有 Web 服务(它是用 Perl 和 SOAP::Lite 实现的)。因此,我有一个给定的 SOAP 响应格式,需要正式定义服务才能为服务的 Java 客户端生成代码。为了针对服务测试 WSDL 文件,我一直在使用 Eclipse 的 Web 服务资源管理器和 soapUI 来为客户端生成代码,我打算使用随 Eclipse (1.3.x) 一起分发的 Axis 版本。

我现在拥有的定义文件确实可以通过 soapUI 访问服务并返回所需的 SOAP 响应,soapUI 也可以断言它符合 Schema,但是如果我从中生成代码并尝试运行代码,事情开始分崩离析。显然,Axis 无法正确识别定义的类型,而只是创建具有“anyType”类型的成员。因此无法正确序列化响应,导致 SAX 解析器出现异常。

当我尝试验证我的 WSDL 文件时,我被告知不允许将一个元素定义为只包含另一个元素的子元素,我认为这是我遇到麻烦的根源。我试图将“prefix_map”元素嵌套到匿名 complexType 中作为序列的单个项目,但现在 soupUI 中的架构合规性断言失败了。那么如何为给定的响应正确定义响应消息的类型呢?

这是我从服务获得的 SOAP 响应:

 <SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/1999/XMLSchema">
<SOAP-ENV:Body>
<namesp1:get_dest_prefixResponse xmlns:namesp1="PortaTAPI">
<prefix_map>
<country xsi:type="xsd:string">SWITZERLAND</country>
<iso_3166_1_a2 xsi:type="xsd:string">CH</iso_3166_1_a2>
<i_group xsi:type="xsd:int">0</i_group>
<destination xsi:type="xsd:long">41445551234</destination>
<i_env xsi:type="xsd:int">2</i_env>
<i_dest xsi:type="xsd:int">10007</i_dest>
<description xsi:type="xsd:string">Customer AG - Wholesale</description>
<i_country_subdivision xsi:type="xsd:int">2855</i_country_subdivision>
<dest_type xsi:null="1"/>
<i_time_zone xsi:null="1"/>
</prefix_map>
</namesp1:get_dest_prefixResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

这是我的 WSDL 文件的相关部分:

 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions
name="PortaTAPI"
targetNamespace="PortaTAPI"
xmlns:tns="PortaTAPI"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<!-- Type Definitions -->
<wsdl:types>
<xsd:schema targetNamespace="PortaTAPI">

<xsd:complexType name="t_prefix_map">
<xsd:all>
<xsd:element name="country" type="xsd:string" minOccurs="1" />
<xsd:element name="iso_3166_1_a2" type="xsd:string" minOccurs="1" />
<xsd:element name="i_group" type="xsd:int" minOccurs="1" />
<xsd:element name="destination" type="xsd:long" minOccurs="1" />
<xsd:element name="i_env" type="xsd:int" minOccurs="1" />
<xsd:element name="i_dest" type="xsd:int" minOccurs="1" />
<xsd:element name="description" type="xsd:string" minOccurs="0" />
<xsd:element name="i_country_subdivision" type="xsd:int" minOccurs="1" />
<xsd:element name="dest_type" type="xsd:string" nillable="true" minOccurs="0" />
<xsd:element name="i_time_zone" type="xsd:string" nillable="true" minOccurs="0" />
</xsd:all>
</xsd:complexType>

<xsd:complexType name="t_tariff_map">
<xsd:all>
<xsd:element name="i_tariff" type="xsd:int"/>
</xsd:all>
</xsd:complexType>


<xsd:element name="get_dest_prefix">
<xsd:complexType>
<xsd:all>
<xsd:element name="prefix" type="xsd:long" minOccurs="1" />
<xsd:element name="i_env" type="xsd:int" minOccurs="1" />
</xsd:all>
</xsd:complexType>
</xsd:element>
<xsd:element name="get_dest_prefixResponse">
<xsd:element name="prefix_map" type="tns:t_prefix_map" />
</xsd:element>
<!-- This causes the Schema compliance assertion of soapUI to fail
<xsd:element name="get_dest_prefixResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="prefix_map" type="tns:t_prefix_map" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
-->

</xsd:schema>
</wsdl:types>

<!-- Messages -->
<wsdl:message name="get_dest_prefixRequest">
<wsdl:part name="parameters" element="tns:get_dest_prefix" />
</wsdl:message>
<wsdl:message name="get_dest_prefixResponse">
<wsdl:part name="result" element="tns:get_dest_prefixResponse" />
</wsdl:message>

<!-- Port -->
<wsdl:portType name="PortaTAPI">

<wsdl:operation name="get_dest_prefix">
<wsdl:input message="tns:get_dest_prefixRequest" />
<wsdl:output message="tns:get_dest_prefixResponse" />
</wsdl:operation>

</wsdl:portType>

<!-- Bindings -->
<wsdl:binding name="PortaTAPISOAP" type="tns:PortaTAPI">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />

<wsdl:operation name="get_dest_prefix">
<soap:operation soapAction="PortaTAPI#get_dest_prefix" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>

</wsdl:binding>

<!-- Service -->
<wsdl:service name="PortaTAPI">
<wsdl:port binding="tns:PortaTAPISOAP" name="PortaTAPISOAP">
<soap:address location="https://62.65.137.91:3113/soap.pl" />
</wsdl:port>
</wsdl:service>

</wsdl:definitions>

这是客户端(由 Axis 生成)抛出的异常:

Sep 14, 2010 2:22:28 PM org.apache.axis.client.Call invoke
SEVERE: Exception:
org.xml.sax.SAXException: Deserializing parameter 'get_dest_prefixResponse': could not find deserializer for type {http://www.w3.org/2001/XMLSchema}anyType
at org.apache.axis.message.RPCHandler.onStartChild(RPCHandler.java:277)
at org.apache.axis.encoding.DeserializationContext.startElement(DeserializationContext.java:1035)
at org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.java:165)
at org.apache.axis.message.MessageElement.publishToHandler(MessageElement.java:1141)
at org.apache.axis.message.RPCElement.deserialize(RPCElement.java:236)
at org.apache.axis.message.RPCElement.getParams(RPCElement.java:384)
at org.apache.axis.client.Call.invoke(Call.java:2467)
at org.apache.axis.client.Call.invoke(Call.java:2366)
at org.apache.axis.client.Call.invoke(Call.java:1812)
at com.netstream.ch.porta.tapi.PortaTAPISOAPStub.get_dest_prefix(PortaTAPISOAPStub.java:261)
at com.netstream.ch.porta.services.DestinationManagementService.getDestination(DestinationManagementService.java:49)
at com.netstream.ch.porta.PortaServicesTest.actionPerformed(PortaServicesTest.java:219)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6263)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6028)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2478)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
AxisFault
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
faultSubcode:
faultString: org.xml.sax.SAXException: Deserializing parameter 'get_dest_prefixResponse': could not find deserializer for type {http://www.w3.org/2001/XMLSchema}anyType
faultActor:
faultNode:
faultDetail:
{http://xml.apache.org/axis/}stackTrace:org.xml.sax.SAXException: Deserializing parameter 'get_dest_prefixResponse': could not find deserializer for type {http://www.w3.org/2001/XMLSchema}anyType

感谢您的帮助!

最佳答案

好的。在您在下面发表评论后,我完善了我的答案。我相信 Axis 正在寻找相关元素的具体类型。由于它没有定义,它假设它是任何类型,然后它很难处理。我会做以下事情:

<xsd:element name="get_dest_prefix">
<xsd:complexType>
<xsd:all>
<xsd:element name="prefix" type="xsd:long" minOccurs="1" />
<xsd:element name="i_env" type="xsd:int" minOccurs="1" />
</xsd:all>
</xsd:complexType>
</xsd:element>
<xsd:element name="get_dest_prefixResponse" type="tns:t_get_dest_prefixResponse"/>
<xsd:complexType name="t_get_dest_prefixResponse">
<xsd:sequence>
<xsd:element name="prefix_map" type="tns:t_prefix_map" minOccurs="1"/>
</xsd:sequence>
</xsd:complexType>

这有帮助吗?这可能会使它更加明确,并允许 Axis 找到它想要的东西。

关于java - 将 WSDL 文件写入现有 Web 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3708039/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com