gpt4 book ai didi

java - 具有相同操作名称和输入类型的 WSDL 会生成不正确的客户端 stub 吗?

转载 作者:行者123 更新时间:2023-12-01 04:40:45 24 4
gpt4 key购买 nike

我有一个具有相同操作名称和请求参数名称的 WSDL 文件。当我使用 WSDL 文件生成客户端 stub 时,端口类生成一个具有 void 返回类型的方法。此外,请求参数从单个对象更改为该单个对象的内容。

将 WSDL 文件上的操作名称更改为其他名称是可行的。但是,我认为修改 WSDL 文件是一个不好的做法。此外,我无法访问实际的网络服务。因此,我也无法更改 Web 服务上的实际操作名称。

有没有办法让wsimport不会与操作名称和请求参数名称混淆?我尝试在 wsimport 中使用 -B-XautoNameResolution 属性,但它没有解决问题。

我的 WSDL 文件如下所示:(如您所见,操作名称和请求参数名称都使用名称“transact”)

<xsd:schema targetNamespace="http://com.example">
<xsd:element name="transact">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="from" type="xsd:string"></xsd:element>
<xsd:element name="to" type="xsd:string"></xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>

<wsdl:message name="requestdata">
<wsdl:part element="tns:transact" name="parameters"/>
</wsdl:message>

<wsdl:message name="responsedata">
<wsdl:part element="tns:responsedata" name="parameters"/>
</wsdl:message>

<wsdl:portType name="portname">
<wsdl:operation name="transact">
<wsdl:input message="tns:requestdata"/>
<wsdl:output message="tns:responsedata"/>
</wsdl:operation>
</wsdl:portType>

生成的类如下所示:(返回类型为 void,即使在 RequestWrapper 中声明了输入类型,transact 方法内声明的方法也不是对象本身。)

@WebMethod(action = "http://com.example/transact")
@RequestWrapper(localName = "transact", targetNamespace = "http://com.example", className = "com.example.Transact")
@ResponseWrapper(localName = "transactresponse", targetNamespace = "http://com.example", className = "com.example.TransactResponse")
public void transact(
@WebParam(name = "to", targetNamespace = "")
String to,
@WebParam(name = "from", targetNamespace = "")
String from);

最佳答案

该应用程序正在正常工作。您所做的是参数处理的包装样式。另一种风格是裸露风格(单部分争论导致1个java对象)

当输入消息的单个部分的元素名称与操作名称相同时,在将 SOAP 请求解码到 Java 时,它会生成多个参数,而不是 1 个封装的 Java 对象。这称为参数处理的“包装样式”。

<wsdl:part element="tns:transact" name="parameters"/>
<wsdl:operation name="transact">

WSDL 绑定(bind)类型仍然保留“文档样式”,因为我们使用单部分(XSD 中的复杂类型)

引用网址:
https://myarch.com/wrappernon-wrapper-web-service-styles-things-you-need-to-know/ http://www.ibm.com/developerworks/library/ws-usagewsdl/

解决方案是更改以下 2 个 XML 条目

<xsd:element name="transactNew">
<wsdl:part element="tns:transactNew" name="parameters"/>

transact更改为transactNew将使其与OperationName(transact)不同,从而解决问题,因为操作名称和单个参数名称现在不同。

关于java - 具有相同操作名称和输入类型的 WSDL 会生成不正确的客户端 stub 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16603849/

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