我如何告诉 wsimport 单独的 WSDL 文件引用相同的对象类?
我有三个不同的 JAX-WS 服务,它们在服务器上使用相同的类(例如 ServiceA
、ServiceB
和 ServiceC
,所有这些都使用MyCommonClass
作为参数)。我们正在开发的另一个模块是使用 wsimport
为这些服务创建客户端,但问题是 wsimport 为每个服务创建单独的 MyCommonClass
实例
- : company.servicea.endpoint.MyCommonClass
com.company.serviceb.endpoint.MyCommonClass
- 等。
我知道我可以使用 wsimport -p
选项来指定每个端点的公共包,但是我想将大多数类保留在单独的包中,但只是为了共享某些公共包。从我读到的内容来看,听起来 JAXB 绑定文件可能会有所帮助,但我还没有弄清楚实现所需结果的确切语法。我想我需要为每个服务提供一个单独的绑定文件(因为我为每个服务调用一次 wsimport),它看起来像这样:
<?xml version="1.0" encoding="UTF-8"?>
<bindings xmlns="http://java.sun.com/xml/ns/jaxb" version="2.1" xmlns:tns="http://endpoint.servicea.company.com/">
<bindings node="//xsd:complexType[@name='myCommonClass']">
<class name="com.company.model.MyCommonClass"/>
</bindings>
</bindings>
我走在正确的轨道上吗?或者您有其他解决方案来解决这个问题吗?
I have three different JAX-WS services which use the same classes on the server (e.g. ServiceA
, ServiceB
, and ServiceC
, all of which use MyCommonClass
as a parameter). Another module we are developing is using wsimport
to create a client for these services, however the problem is that wsimport creates separate instances of MyCommonClass
for each service:
com.company.servicea.endpoint.MyCommonClass
com.company.serviceb.endpoint.MyCommonClass
- etc.
I know that I could use the wsimport -p
option to specify a common package for each endpoint, however I'd like to keep most of the classes in separate packages, but just to share certain common ones. From what I have read it sounds like a JAXB bindings file(s) might be able to help, but I haven't yet figured out the exact syntax to achieve the desired result. I think I'll need a separate bindings file for each service (as I call wsimport once for each one), which looks something like this:
<?xml version="1.0" encoding="UTF-8"?>
<bindings xmlns="http://java.sun.com/xml/ns/jaxb" version="2.1" xmlns:tns="http://endpoint.servicea.company.com/">
<bindings node="//xsd:complexType[@name='myCommonClass']">
<class name="com.company.model.MyCommonClass"/>
</bindings>
</bindings>
Am I on the right track? Or do you have any alternative solutions to the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 xsd 中定义公共类并将其导入到服务 WSDL 中。
然后使用模式自定义将此模式中的定义生成到单独的包中,例如“com.company.model”
...
参考:http://jax-ws.java.net/jax-ws-21-ea1/docs/customizations.html#2.6_Class_Customization
Define your common classes in an xsd and import it in to the service WSDL's.
Then use the schema customization to generate definitions in this schema in to a separate package like "com.company.model"
...
ref: http://jax-ws.java.net/jax-ws-21-ea1/docs/customizations.html#2.6_Class_Customization