将两个 WSDL 的类型映射到一个 Java 类

发布于 2024-12-02 18:24:54 字数 2553 浏览 1 评论 0原文

我正在使用来自一家公司的两个 Web 服务,每个服务都有自己的 wsdl。我正在使用 wsimport 生成 java 类。

我发现这两个 wsdl 有很多重叠,但使用的名称不同。例如,当发生错误时,两个服务都会返回错误消息列表。但是这两个服务对返回的列表使用不同的名称。请参阅 wsdl 的两个小节

  .
  .
  <s:element name="LoadResponse">
    <s:complexType>
      <s:sequence>
        <s:element minOccurs="0" maxOccurs="1" name="LoadResult" type="tns:ArrayOfMessageOfHierarchyLoadMessage" />
        <s:element minOccurs="0" maxOccurs="1" name="hierarchy" type="tns:Hierarchy" />
      </s:sequence>
    </s:complexType>
  </s:element>
  <s:complexType name="ArrayOfHierarchyLoadMessage">
    <s:sequence>
      <s:element minOccurs="0" maxOccurs="unbounded" name="HierarchyLoadMessage" nillable="true" type="tns:HierarchyLoadMessage" />
    </s:sequence>
  </s:complexType>
  <s:complexType name="HierarchyLoadMessage">
    <s:sequence>
      <s:element minOccurs="1" maxOccurs="1" name="Type" type="tns:MessageType" />
      <s:element minOccurs="0" maxOccurs="1" name="Text" type="s:string" />
      <s:element minOccurs="0" maxOccurs="1" name="Parameters" type="tns:ArrayOfString" />
    </s:sequence>
  </s:complexType>
  .
  .

和另一个 wsdl 的小节

  .
  .
  <s:element name="SearchResponse">
    <s:complexType>
      <s:sequence>
        <s:element minOccurs="0" maxOccurs="1" name="SearchResult" type="tns:ArrayOfMessageOfErrorCodes" />
        <s:element minOccurs="0" maxOccurs="1" name="data" type="tns:FinderData" />
      </s:sequence>
    </s:complexType>
  </s:element>
  <s:complexType name="ArrayOfErrorCodes">
    <s:sequence>
      <s:element minOccurs="0" maxOccurs="unbounded" name="ErrorCodes" nillable="true" type="tns:ErrorCodes" />
    </s:sequence>
  </s:complexType>
  <s:complexType name="ErrorCodes">
    <s:sequence>
      <s:element minOccurs="1" maxOccurs="1" name="Type" type="tns:MessageType" />
      <s:element minOccurs="0" maxOccurs="1" name="Text" type="s:string" />
      <s:element minOccurs="0" maxOccurs="1" name="Parameters" type="tns:ArrayOfString" />
    </s:sequence>
  </s:complexType>
  .
  .

正如您所看到的重叠类型是

ArrayOfMessageOfHierarchyLoadMessage and ArrayOfMessageOfHierarchyLoadMessage
MessageOfHierarchyLoadMessage and MessageOfErrorCodes

您能告诉我是否可以使用绑定文件来映射两个 wsdl 中的相同类型,这样 wsimport 只会生成一个 java上课吗?

I'm using two web services from one company which each have their own wsdl. I'm using wsimport to generate the java classes.

I found that there is a lot of overlap in the two wsdl's but the used names are different. For example when an error occurs both services return a list of error messages. But the two services use different names for the returned lists. See two subsections of the wsdl's

  .
  .
  <s:element name="LoadResponse">
    <s:complexType>
      <s:sequence>
        <s:element minOccurs="0" maxOccurs="1" name="LoadResult" type="tns:ArrayOfMessageOfHierarchyLoadMessage" />
        <s:element minOccurs="0" maxOccurs="1" name="hierarchy" type="tns:Hierarchy" />
      </s:sequence>
    </s:complexType>
  </s:element>
  <s:complexType name="ArrayOfHierarchyLoadMessage">
    <s:sequence>
      <s:element minOccurs="0" maxOccurs="unbounded" name="HierarchyLoadMessage" nillable="true" type="tns:HierarchyLoadMessage" />
    </s:sequence>
  </s:complexType>
  <s:complexType name="HierarchyLoadMessage">
    <s:sequence>
      <s:element minOccurs="1" maxOccurs="1" name="Type" type="tns:MessageType" />
      <s:element minOccurs="0" maxOccurs="1" name="Text" type="s:string" />
      <s:element minOccurs="0" maxOccurs="1" name="Parameters" type="tns:ArrayOfString" />
    </s:sequence>
  </s:complexType>
  .
  .

and the subsection of the other wsdl

  .
  .
  <s:element name="SearchResponse">
    <s:complexType>
      <s:sequence>
        <s:element minOccurs="0" maxOccurs="1" name="SearchResult" type="tns:ArrayOfMessageOfErrorCodes" />
        <s:element minOccurs="0" maxOccurs="1" name="data" type="tns:FinderData" />
      </s:sequence>
    </s:complexType>
  </s:element>
  <s:complexType name="ArrayOfErrorCodes">
    <s:sequence>
      <s:element minOccurs="0" maxOccurs="unbounded" name="ErrorCodes" nillable="true" type="tns:ErrorCodes" />
    </s:sequence>
  </s:complexType>
  <s:complexType name="ErrorCodes">
    <s:sequence>
      <s:element minOccurs="1" maxOccurs="1" name="Type" type="tns:MessageType" />
      <s:element minOccurs="0" maxOccurs="1" name="Text" type="s:string" />
      <s:element minOccurs="0" maxOccurs="1" name="Parameters" type="tns:ArrayOfString" />
    </s:sequence>
  </s:complexType>
  .
  .

As you can see the overlapping types are

ArrayOfMessageOfHierarchyLoadMessage and ArrayOfMessageOfHierarchyLoadMessage
MessageOfHierarchyLoadMessage and MessageOfErrorCodes

Can you tell me if it is possible, using binding files, to map the identical types in the two wsdl's such wsimport will only generate one java class for it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

极致的悲 2024-12-09 18:24:54

您需要问自己的问题是:只拥有一个适用于两种不同 Web 服务的类是个好主意吗?如果您只有一个类别,如果其中一家公司更改其服务会发生什么情况。你不仅要修改他们的ws接口,还要修改第二家公司的接口。

您可能认为您希望分解出尽可能多的代码,但从长远来看,像这样将两个 Web 服务捆绑在一起可能不是一个好主意。随着时间的推移,界面可能会分开。我认为在这种情况下重复代码是可以接受的。

您可能已经想到了这一点,但我要做的是使用适配器模式。因此,您将拥有三个类:代码中随处使用的泛型类 (GenericErrorList);两个是从各自的 wsdls(CompanyOneErrorList 和 CompanyTwoErrorList)生成的。有一种转换方法,它采用 CompanyOneErrorList 并创建 GenericErrorList。其他公司也一样。

除非您有充分的理由将这两个实现结合在一起,否则我会避免这样做。

The question you need to ask yourself is: Is it a good idea to only have one class which applies to two different web services? If you have a single class, what happens if one of the companies changes its service. You not only have to modify the interface to their ws, but the second companies interface as well.

You could take the view that you would like to factor out as much code as possible, but tying the two web services together like this may not be a good idea in the long term. The interfaces may move apart over time. I think it is acceptable to duplicate code in this instance.

You've probably already thought of this, but what I would do is use an Adaptor pattern. So you would have three classes: the generic class (GenericErrorList) used everywhere in your code; and two which are generated from the respective wsdls(CompanyOneErrorList and CompanyTwoErrorList). There is a conversion method which takes a CompanyOneErrorList and creates a GenericErrorList. Same for the other company.

Unless you have a really good reason to tie the two implementations together, I would avoid doing so.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文