Java 如何获取我的 WSDL 的 URL?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19180607/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 14:48:39  来源:igfitidea点击:

How to get the URL of my WSDL?

javaweb-servicestomcatjax-ws

提问by tsukanomon

I have created a very simple web service using Netbeans, Java EE6, JAX-WS and TomCat. It just have one @WebMethod getWsdlURL(), which is supposed to return the URL of my wsdl, and it should be something similar to:

我使用 Netbeans、Java EE6、JAX-WS 和 TomCat 创建了一个非常简单的 Web 服务。它只有一个@WebMethod getWsdlURL(),它应该返回我的 wsdl 的 URL,它应该类似于:

http://192.168.70.44:8088/SimpleWebService/WebService?wsdl

However I don't have any idea on how to do that.

但是我不知道如何做到这一点。

Can anyone help me?

谁能帮我?

采纳答案by david99world

Don't add your own service to return the URL. Depend on the runtime, that already supplies it.

不要添加自己的服务来返回 URL。取决于已经提供它的运行时。

Just open the url in a browser. The url would be....

只需在浏览器中打开网址即可。网址将是....

http://<hostname>:<port>/<webappname>/<servletEndpoint>?wsdl

回答by Ujjwal

To add to answer of david99world, you can look for the endpoint url-pattern in sun-jaxws.xml configuration file present in WEB-INF dir.

要添加到 david99world 的答案,您可以在 WEB-INF 目录中的 sun-jaxws.xml 配置文件中查找端点 url-pattern。

The file may have a definition like:

该文件可能具有如下定义:

<endpoints xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime" version="2.0">

    <endpoint name="ws/MyService" implementation="com.test.ws.services.MyService"
        url-pattern="/ws/MyService" enable-mtom="false" />

</endpoints>

回答by VGR

If you are generating classes from a WSDL when you build, your service class will extend javax.xml.ws.Service and therefore will inherit the getWSDLDocumentLocationmethod.

如果您在构建时从 WSDL 生成类,您的服务类将扩展 javax.xml.ws.Service 并因此将继承该getWSDLDocumentLocation方法。