WSImport为多个Dynamics CRM 4.0 WSDL生成冲突的XMLType

Nic*_*een 9 jax-ws jaxb dynamics-crm wsimport dynamics-crm-4

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

[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
Run Code Online (Sandbox Code Playgroud)

979行告诉我们:

<s:element name="RetrieveResponse">
    <s:complexType>
      <s:sequence>
        <s:element name="RetrieveResult" type="s3:BusinessEntity" />
      </s:sequence>
    </s:complexType>
  </s:element>
Run Code Online (Sandbox Code Playgroud)

第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>
Run Code Online (Sandbox Code Playgroud)

两个部分都在同一名称空间中.两者都将生成为RetrieveResponse.class,因此它们会发生碰撞.我找到了这个问题的解决方案,即JAX-B绑定xml文件:

<bindings node="//xsd:complexType[@name='RetrieveResponse']">
  <jaxb:class name="RetrieveResponseType"/>
</bindings>
Run Code Online (Sandbox Code Playgroud)

这有效(不确定这是否是正确的方法..?)..

所以在此之后,我成功地创建了一些成功的Web服务调用,这很棒!

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

所以我接下来要做的就是基于它的WSDL生成元数据服务的类.生成的类的结果不是我们除外.例如,它生成一个类'com.microsoft.schemas.crm._2007.webservices.ExecuteResponse'.但是这个类也存在于CrmService生成的类的完全相同的包中.两者之间的差异是:

Metadataservice ExecuteReponse:

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

   @XmlElement(name = "Response")
   protected MetadataServiceResponse response;
etc...
Run Code Online (Sandbox Code Playgroud)

CrmService ExecuteReponse:

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

   @XmlElement(name = "Response", required = true)
   protected ResponseType response;
etc...
Run Code Online (Sandbox Code Playgroud)

现在这个类只是一个例子(另一个例子是CrmAuthenticationToken),它几乎完全与另一个类重复.为了能够使用相同的类,我在CrmService类中添加了一个包后缀(显示为前缀.).所以现在当我尝试调用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
Run Code Online (Sandbox Code Playgroud)

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

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

谢谢你的时间!

flu*_*lup 1

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

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

对于微软来说,他们为不同的服务定义不同的定义是不礼貌的。这使得很难获取一项服务的答案并将其发送到另一项服务。

如果服务共享一个或多个通用模式,您可以先使用 xjc 编译这些模式。然后,您可以向 wsimport 提供一个所谓的 Episode 文件,告诉它使用这些类而不是生成新的类。请参阅地铁指南。这是一个相当大的难题,我可以根据经验告诉你,我遇到了错误 JAXB-829,xjc 忘记在剧集文件中生成 if-exists 属性。

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