【问题标题】:WSImport generates conflicting XMLTypes for multiple Dynamics CRM 4.0 WSDL'sWSImport 为多个 Dynamics CRM 4.0 WSDL 生成冲突的 XMLType
【发布时间】:2012-05-17 22:37:49
【问题描述】:

我目前正在使用 Dynamics CRM 4.0 网络服务。我做的第一件事是根据 Web 服务的 WSDL 使用 wsimport 为 Java/JAX-WS 生成正确的类。在生成类时我遇到了一些错误:

[ERROR] A class/interface with the same name
"com.microsoft.schemas.crm._2007.webservices.RetrieveResponse" is already in use. Use a class customization to resolve this conflict.
  line 979 of file://src/main/webapp/WEB-INF/classes/META-INF/wsdl/CrmServiceWsdl.wsdl

[ERROR] (Relevant to above error) another "RetrieveResponse" is generated from here.
  line 12274 of file://src/main/webapp/WEB-INF/classes/META-INF/wsdl/CrmServiceWsdl.wsdl

第 979 行告诉我们:

<s:element name="RetrieveResponse">
    <s:complexType>
      <s:sequence>
        <s:element name="RetrieveResult" type="s3:BusinessEntity" />
      </s:sequence>
    </s:complexType>
  </s:element>

第 12274 行给了我们:

<s:complexType name="RetrieveResponse">
    <s:complexContent mixed="false">
      <s:extension base="tns:Response">
        <s:sequence>
          <s:element ref="s3:BusinessEntity" />
        </s:sequence>
      </s:extension>
    </s:complexContent>
  </s:complexType>

这两个部分都在同一个命名空间中。两者都将作为 RetrieveResponse.class 生成,因此它们正在碰撞。我找到了解决这个问题的方法,那就是 JAX-B 绑定 xml 文件:

<bindings node="//xsd:complexType[@name='RetrieveResponse']">
  <jaxb:class name="RetrieveResponseType"/>
</bindings>

这行得通(不确定这是否是正确的方法..?)..

因此,在此之后,我成功地创建了一些对 web 服务的调用,这很棒!

现在问题来了:动态 crm 中的一些业务实体使用类 Picklist。此类实体可通过元数据服务查询:http://msdn.microsoft.com/en-us/library/bb890248.aspx

所以我接下来要做的就是再次为元数据服务生成类,基于它的 WSDL。生成的类的结果与我们不同。例如,它生成一个类“com.microsoft.schemas.crm._2007.webservices.ExecuteResponse”。但是这个类也存在于 CrmService 生成的类的完全相同的包中。两者的区别是:

元数据服务执行响应:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "response"
})
@XmlRootElement(name = "ExecuteResponse")
public class ExecuteResponse {

   @XmlElement(name = "Response")
   protected MetadataServiceResponse response;
etc...

CrmService 执行响应:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "response"
})
@XmlRootElement(name = "ExecuteResponse")
public class ExecuteResponse {

   @XmlElement(name = "Response", required = true)
   protected ResponseType response;
etc...

现在这个类只是一个例子(另一个例子是CrmAuthenticationToken),它是另一个类的几乎完全相同的副本。为了能够使用相同的类,我在 CrmService 类中添加了一个包后缀(显示为 prefix。)。 所以现在当我尝试调用 CrmService 时,我得到了以下异常:

Two classes have the same XML type name "{http://schemas.microsoft.com/crm/2007/CoreTypes}CrmAuthenticationToken". Use @XmlType.name and @XmlType.namespace to assign different names to them.
this problem is related to the following location:
    at com.microsoft.schemas.crm._2007.coretypes.CrmAuthenticationToken
    at public com.microsoft.schemas.crm._2007.coretypes.CrmAuthenticationToken *prefix*.com.microsoft.schemas.crm._2007.coretypes.ObjectFactory.createCrmAuthenticationToken()
    at *prefix*.com.microsoft.schemas.crm._2007.coretypes.ObjectFactory
this problem is related to the following location:
    at *prefix*.com.microsoft.schemas.crm._2007.coretypes.CrmAuthenticationToken
    at public javax.xml.bind.JAXBElement *prefix*.com.microsoft.schemas.crm._2007.webservices.ObjectFactory.createCrmAuthenticationToken(*prefix*.com.microsoft.schemas.crm._2007.coretypes.CrmAuthenticationToken)
    at *prefix*.com.microsoft.schemas.crm._2007.webservices.ObjectFactory

我个人认为他们将具有相同名称的不同类放在同一个包结构中很奇怪。这意味着您永远不能同时使用这 2 个网络服务..

这是微软的一个 WSimport 错误还是我的一个愚蠢的错误?希望有人能帮我解决这个问题!

感谢您的宝贵时间!

【问题讨论】:

    标签: jaxb jax-ws dynamics-crm dynamics-crm-4 wsimport


    【解决方案1】:

    这是 Microsoft 的不一致加上 wsimport 有点难以使用。

    PickList 和 CRMAuthenticationToken 听起来像是自定义数据类型,您希望它们能够在服务之间重用。 您还希望某些特定于 CRM 的实体(例如,客户或企业或地址)在服务之间得到重用。

    在微软方面,他们为不同的服务定义了不同的定义是不礼貌的。这使得很难将一个服务的答案发送到另一个服务。

    如果服务共享一个或多个通用架构,您可以先使用 xjc 编译这些架构。然后,您可以向 wsimport 提供一个所谓的剧集文件,告诉它使用这些类而不是生成新的类。见the metro guide。这真是一个谜,我可以从经验告诉你,我遇到了错误 JAXB-829,xjc 忘记在剧集文件中生成 if-exists 属性。

    我会做什么,我会将每个 wsdl 编译到自己的包中,并将生成的类视为简单的非智能数据传输对象。 如果我想将我刚刚从一项服务中检索到的对象发送到另一项服务,我会在两者之间进行转换。 如果这导致代码非常笨拙,或者如果您希望向某些实体添加逻辑,我建议您为要共享的实体编写自己的适当模型类,并在 Web 服务中编写与 DTO 对象之间的转换器您希望与它们一起使用的软件包。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-21
      相关资源
      最近更新 更多