如何告诉wsimport单独的WSDL文件引用相同的对象类? [英] How can I tell wsimport that separate WSDL files are referring to the same object classes?

查看:109
本文介绍了如何告诉wsimport单独的WSDL文件引用相同的对象类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有三种不同的JAX-WS服务,它们在服务器上使用相同的类(例如 ServiceA ServiceB ServiceC ,所有这些都使用 MyCommonClass 作为参数)。我们正在开发的另一个模块是使用 wsimport 为这些服务创建一个客户端,但问题是wsimport会创建 MyCommonClass

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。

我知道我可以使用 wsimport -p 选项指定一个公共包每个端点,但是我想将大多数类保留在单独的包中,但只是为了共享某些常见的类。从我所看到的,它听起来像一个JAXB绑定文件可能会有所帮助,但我还没有找到确切的语法来实现所需的结果。我想我需要为每个服务单独的绑定文件(因为我为每个服务调用wsimport一次),看起来像这样:

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?

推荐答案

在xsd中定义你的公共类并将其导入服务WSDL的。
然后使用模式自定义在此模式中生成定义到单独的包中,如com.company.model

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"

<jxb:bindings
   xmlns:xsd="http://www.w3.org/2001/XMLSchema"
   xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
   version="1.0">
    <jxb:bindings schemaLocation="model.xsd" node="/xsd:schema">
        <jxb:schemaBindings>
        <jxb:package name="com.company.model"/>
        </jxb:schemaBindings>
</jxb:bindings>

...

ref:< a href =http://jax-ws.java.net/jax-ws-21-ea1/docs/customizations.html#2.6_Class_Customization =nofollow> http://jax-ws.java.net /jax-ws-21-ea1/docs/customizations.html#2.6_Class_Customization

这篇关于如何告诉wsimport单独的WSDL文件引用相同的对象类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆