在 JAX-WS 客户端 .jar 中嵌入 Web 服务的 WSDL
我有一个几年前用 C++ 创建的 Web 服务,由 .NET 客户端使用 C# 的“wsdl.exe”来生成客户端存根。由于各种原因,我现在还需要一个 Java 客户端,并且愿意将使用限制为 Java 6 (JDK 1.6) 和 JAX-WS。生成的存根工作正常,即使打包在 .jar 中也是如此,但我对 JAX-WS Web 服务客户端想要部署的方式遇到了问题。看起来我遇到的问题是可以解决的,但建议的方法似乎都不起作用。
JAX-WS 期望 WSDL 是可访问的,最好是从网络访问,因为它每次启动时都会解析 WSDL 以创建绑定。就像 Creating a web-service client with 中的 jgrowl 一样已知但无法访问的 wsdl,客户端可能无法访问 JAX-WS 使用的 URL 处的 WSDL(可能是构建计算机上的文件或指向本地主机的指针)。我想将 WSDL 发送到客户端 .jar 中,但最简单的解决方案 (-wsdllocation "/path/to/wsdl/in/jar.wsdl"
) 会打印出我不想要的警告出现。
我也希望不让客户做类似 jgrowl 找到的解决方案的事情,它似乎有效,但并不只是有效。 Google 上找到的文章主要涉及服务器 WSDL 位置,但建议客户端应该能够使用 META-INF/jax-ws-catalog.xml
文件来转换 -wsdllocation 中使用的 URL
到 .jar 文件中的路径,但这些在我们的测试中似乎不起作用。
是否有一个“秘诀”,以便我可以将 WSDL 放入 .jar 中的某个位置,并使 JAX-WS 客户端正常工作,而无需客户端用户付出额外的努力,也不会发出任何警告?
I have a web service that was created several years ago in C++ and is consumed by a .NET client using C#'s "wsdl.exe" to generate the client stubs. For a variety of reasons, I now also need a Java client and am willing to restrict usage to Java 6 (JDK 1.6) with JAX-WS. The generated stubs work fine, even when packaged in a .jar, but I'm having a problem with the way that JAX-WS web service clients want to be deployed. It looks like the problem I'm having is solvable, but none of the suggested ways seems to work.
JAX-WS expects the WSDL to be accessible, preferably from the network, as it parses the WSDL on startup every time to create the bindings. Like jgrowl in Creating a web-service client with a known but inaccessible wsdl, the client may not have access to the WSDL at the URL that JAX-WS uses (which will likely be a file on the build machine or a pointer to localhost). I want to ship the WSDL inside the client .jar, but the simplest solution (-wsdllocation "/path/to/wsdl/in/jar.wsdl"
) prints out a warning that I do not want to show up.
I would also prefer not having the client do something like the solution jgrowl found, which appears to work but doesn't Just Work. Articles found on Google mostly address server WSDL locations, but suggest that clients should be able to work with META-INF/jax-ws-catalog.xml
files that translate the URL used in -wsdllocation
to a path in the .jar file, but those do not seem to work in our testing.
Is there a "recipe" so that I can put the WSDL inside the .jar somewhere and have a JAX-WS client just work with no extra effort on the part of the client user and with no warnings?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您不想在构造函数中设置 WSDL 的 URL,您也许可以依赖生成的工件的行为。当我使用以下
-wsdlLocation
:以下内容在服务代码中作为静态初始化程序生成:
这基本上会执行与您找到的解决方案相同的操作,但使用默认构造函数。 WSDL 必须是
wsdl
文件夹中类路径上的资源。这种方法不会对我发出任何警告。
我认为规范中没有定义此行为——至少,我没能找到它。我相信这是我的 JDK 中
wsimport
工具的实现细节。如果您要部署到 Java EE 容器,您有更多选择 - 请参阅 JSR 109。我相信这就是 jax-ws-catalog.xml 发挥作用的地方。
If you prefer not to set the URL to the WSDL in the constructor, you might be able to rely on the behaviour of the generated artifacts. When I use the following
-wsdlLocation
:The following is generated in the service code as a static initializer:
This will essentially do the same thing as the solution you found, but with the default constructor. The WSDL needs to be a resource on the classpath in the the
wsdl
folder.This approach issues no warnings for me.
I don't think this behaviour is defined in the spec - at least, I haven't been able to find it. I believe it is an implementation detail of the
wsimport
tool in my JDK.You have more options if you're deploying to a Java EE container - see JSR 109. I believe this is where
jax-ws-catalog.xml
comes into play.