gpt4 book ai didi

java - 如何更改 JAX-WS webservice 的地址位置

转载 作者:搜寻专家 更新时间:2023-10-31 08:17:39 25 4
gpt4 key购买 nike

我们目前已经公开了具有以下 URL 的 JAX-RPC 网络服务

http://xx.xx.xx.xx/myservice/MYGatewaySoapHttpPort?wsdl

我们通过从 WSDL 之上生成 WebService 将 webservice 迁移到 JAX-WS

但是可以从以下 URL 访问新的网络服务

http://xx.xx.xx.xx/myservice/MYGateway?wsdl

如何让我的 JAX-WS 网络服务可以通过前面提到的相同 URL 访问?这样我们的客户就没有任何问题。

更新:

我创建的 WSDL 服务元素符合预期

<WL5G3N0:service name="MyGateway">
<WL5G3N0:port binding="WL5G3N2:MyGatewaySoapHttp" name="MyGatewaySoapHttpPort">
<WL5G3N3:address location="http://xx.xx.xx/myservice/MyGatewaySoapHttpPort"/>
</WL5G3N0:port>
</WL5G3N0:service>

但是 JAX-WS 的 WSDL 不一样,这个 WSDL 是自动生成的。

<WL5G3N0:service name="MyGateway">
- <WL5G3N0:port binding="WL5G3N2:MyGatewaySoapHttp" name="MyGatewaySoapHttpPort">
<WL5G3N3:address location="http://xx.xx.xx/myservice/MyGateway" />
</WL5G3N0:port>
</WL5G3N0:service

我使用 Oracle Eclipse Indigo 创建了网络服务。

我可以更改任何注释吗?

问候,

最佳答案

这允许在客户端中设置端点:

MYGateway service = new MYGateway();
MYGatewaySoapServiceHttpPort port = service.getMYGatewaySoapServiceHttpPort();
BindingProvider bp = (BindingProvider) port;
bp.getRequestContext().put(
BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
"http://xx.xx.xx.xx/myservice/MYGateway");

(感谢用户 FoGH 指出端点应该指示服务,而不是 WSDL)

编辑:这里有一些关于设置 org.codehaus.mojo.jaxws-maven-plugin 的更多信息:

在你的 pom.xml 中:

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<executions>
<execution>
<id>MyGateway</id>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<wsdlDirectory>src/main/resources/META-INF/wsdl</wsdlDirectory>
<wsdlFiles>
<wsdlFile>MyGateway.wsdl</wsdlFile>
</wsdlFiles>
<wsdlLocation>MyGatewaySystemId</wsdlLocation>
<!-- Line below to avoid regeneration bug if you have multiple executions -->
<staleFile>${project.build.directory}/jaxws/stale/wsdl.MyGateway.done</staleFile>
</configuration>
</execution>
</executions>
</plugin>

在 ./src/main/resources/META-INF/jax-ws-catalog.xml 中:

<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
<system systemId="MyGatewaySystemId" uri="wsdl/MyGateWay.wsdl"/>
</catalog>

将您的 WSDL 放入 ./src/main/resources/META-INF/wsdl/MyGateway.wsdl

因此插件配置中的 wsdlLocation 引用了 jax-ws-catalog.xml 文件中的条目。此文件使用相对目录表示法指向实际的 WSDL 文件。

值“MyGatewaySystemId”最终作为位置出现在生成的 Web 服务代码中。所以您可以将其更改为 WSDL 的实际 URL。请注意,您需要配置您的 pom 来为构建环境(开发、测试、生产)设置正确的 URL,以使其始终如一地工作。正确方向的指针是使用 Maven 配置文件。

提示:下载在线 WSDL(和相关 XSD)副本的一种简单方法是为其创建一个 SoapUI 项目,然后转到“WSDL 内容”选项卡。

关于java - 如何更改 JAX-WS webservice 的地址位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11576615/

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