【问题标题】:How to change address location of JAX-WS webservice如何更改 JAX-WS Web 服务的地址位置
【发布时间】:2012-07-20 09:29:11
【问题描述】:

我们目前已经通过以下 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 webservice 可以通过前面提到的相同 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 创建了 Web 服务。

我可以用任何注释进行更改吗?

问候,

【问题讨论】:

    标签: java web-services jax-ws jax-rpc


    【解决方案1】:

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

    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 内容”选项卡。

    【讨论】:

    • 您提供的代码将帮助客户。但我想在服务器上更改网络服务的地址。所以客户端不会有任何变化。
    • 您的工具似乎正在生成修改后的 WSDL。您应该查看文档,看看您是否可以影响它生成的位置值。
    • 是的,我正在寻找如何影响位置价值。
    【解决方案2】:

    我们错过了非常基本的一点,web.xml 中的 servlet 映射成功了。详情请看以下链接

    http://pic.dhe.ibm.com/infocenter/wasinfo/v6r1/index.jsp?topic=%2Fcom.ibm.websphere.wsfep.multiplatform.doc%2Finfo%2Fae%2Fae%2Ftwbs_customwebxml.html

    【讨论】:

    • 链接失效了。您能否描述您的解决方案,因为它是公认的答案。
    【解决方案3】:

    检查您的 JAX-WS WSDL 文件的 Service 元素。

    <service name="Hello_Service">
          <documentation>WSDL File for HelloService</documentation>
          <port binding="tns:Hello_Binding" name="Hello_Port">
             <soap:address
                location="http://www.examples.com/SayHello/">
          </port>
       </service>
    

    location 元素指定通过哪个端口访问 Web 服务。

    阅读this

    【讨论】:

      猜你喜欢
      • 2016-06-22
      • 1970-01-01
      • 2013-07-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-16
      相关资源
      最近更新 更多