java 如何更改 JAX-WS webservice 的地址位置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11576615/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to change address location of JAX-WS webservice
提问by ImranRazaKhan
We have currently exposed JAX-RPC webservice with following URL
我们目前已使用以下 URL 公开 JAX-RPC Web 服务
http://xx.xx.xx.xx/myservice/MYGatewaySoapHttpPort?wsdl
http://xx.xx.xx.xx/myservice/MYGatewaySoapHttpPort?wsdl
We migrated webservice to JAX-WS by generating WebService from above WSDL
我们通过从上面的 WSDL 生成 WebService 将 webservice 迁移到 JAX-WS
But new webservice is accessible from following URL
但是可以从以下 URL 访问新的网络服务
http://xx.xx.xx.xx/myservice/MYGateway?wsdl
http://xx.xx.xx.xx/myservice/MYGateway?wsdl
How i can make my JAX-WS webservice to be accessible by same URL mentioned first? so that our customer dont have any problem.
如何使我的 JAX-WS Web 服务可以通过首先提到的相同 URL 访问?以便我们的客户没有任何问题。
Update:
更新:
Service Element of WSDL from which i created is as per expectation
我创建的 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>
But WSDL of JAX-WS is not same and this WSDL is auto generated.
但是 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
I created webservice with Oracle Eclipse Indigo.
我使用 Oracle Eclipse Indigo 创建了网络服务。
Can i change with any annotaion?
我可以更改任何注释吗?
Regards,
问候,
采纳答案by ImranRazaKhan
We missed very basic point, servlet mapping in web.xml did all trick. for details please find below link
我们错过了非常基本的一点,web.xml 中的 servlet 映射可以解决所有问题。详情请参阅以下链接
回答by Adriaan Koster
This allows setting the endpoint in the client:
这允许在客户端设置端点:
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");
(thanks to user FoGHfor pointing out that the endpoint should indicate the service, not the wsdl)
(感谢用户FoGH指出端点应该指示服务,而不是 wsdl)
EDIT: here is some more information about setting up the org.codehaus.mojo.jaxws-maven-plugin:
编辑:这里有一些关于设置 org.codehaus.mojo.jaxws-maven-plugin 的更多信息:
In your pom.xml:
在你的 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>
In ./src/main/resources/META-INF/jax-ws-catalog.xml:
在 ./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>
Put your WSDL in ./src/main/resources/META-INF/wsdl/MyGateway.wsdl
将您的 WSDL 放在 ./src/main/resources/META-INF/wsdl/MyGateway.wsdl
So the wsdlLocation in the plugin configuration refers to an entry in the jax-ws-catalog.xml file. This file points to the actual WSDL file using a relative directory notation.
所以插件配置中的 wsdlLocation 是指 jax-ws-catalog.xml 文件中的一个条目。该文件使用相对目录表示法指向实际的 WSDL 文件。
The value 'MyGatewaySystemId' ends up in the generated web service code as the location. So you could change this to the actual URL of the WSDL. Note that you would need configure your pom to set the correct URL for the build environment (dev, test, prod) for this to work consistently. A pointer in the right direction for this is to use maven profiles.
值“MyGatewaySystemId”在生成的 Web 服务代码中作为位置结束。因此,您可以将其更改为 WSDL 的实际 URL。请注意,您需要配置 pom 来为构建环境(dev、test、prod)设置正确的 URL,以使其始终如一地工作。正确方向的一个指针是使用 maven 配置文件。
Tip: an easy way to download a copy of an online WSDL (and related XSD's) is to create a SoapUI project for it and then go to the 'WSDL content' tab.
提示:下载在线 WSDL(和相关 XSD)副本的一种简单方法是为其创建一个 SoapUI 项目,然后转到“WSDL 内容”选项卡。
回答by Pokuri
Check your Service
element of your JAX-WS WSDL file.
检查Service
JAX-WS WSDL 文件的元素。
<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 element specifies through which port to access the Web service.
location 元素指定通过哪个端口访问 Web 服务。
read this
读这个