如何更改JAX-WS Web服务的地址位置

Imr*_*han 5 java web-services jax-ws jax-rpc

我们目前使用以下URL公开了JAX-RPC Web服务

HTTP://xx.xx.xx.xx/myservice/MYGatewaySoapHttpPort WSDL

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

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

HTTP://xx.xx.xx.xx/myservice/MYGateway WSDL

我如何能够通过首先提到的相同URL访问我的JAX-WS Web服务?这样我们的客户就没有任何问题.

更新:

我创建的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>
Run Code Online (Sandbox Code Playgroud)

但是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
Run Code Online (Sandbox Code Playgroud)

我使用Oracle Eclipse Indigo创建了webservice.

我能改变任何注释吗?

问候,

Adr*_*ter 12

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

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");
Run Code Online (Sandbox Code Playgroud)

(感谢用户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>
Run Code Online (Sandbox Code Playgroud)

在./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>
Run Code Online (Sandbox Code Playgroud)

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

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

值"MyGatewaySystemId"最终在生成的Web服务代码中作为位置.因此,您可以将其更改为WSDL的实际URL.请注意,您需要配置pom以设置构建环境(dev,test,prod)的正确URL,以使其始终如一地工作.正确方向的指针是使用maven配置文件.

提示:下载在线WSDL(及相关XSD)副本的简便方法是为其创建SoapUI项目,然后转到"WSDL内容"选项卡.


Imr*_*han 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

  • 该链接不再有效。您能否描述您的解决方案,因为它是公认的答案。 (2认同)