WSImport为多个Dynamics CRM 4.0 WSDL生成冲突的XMLType [英] WSImport generates conflicting XMLTypes for multiple Dynamics CRM 4.0 WSDL's

查看:131
本文介绍了WSImport为多个Dynamics CRM 4.0 WSDL生成冲突的XMLType的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm currently working with the Dynamics CRM 4.0 webservice. First thing I did, was generating the right classes with wsimport for Java/JAX-WS based on the WSDL of the webservice. While generating the classes I got some errors:

[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行告诉我们:

And line 12274 gives us:

<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文件:

Both parts are in the same namespace. Both will be generated as RetrieveResponse.class and so they are colliding. I've found a solution for this problem which is the JAX-B binding xml file:

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

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

This works (not sure if this is the correct approach..?)..

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

So after this, I've managed to create some successful calls to the webservice, which is great!

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

Now comes the problem: some business entities in dynamics crm uses the class Picklist. This type of entity can be queried with the Metadata service: http://msdn.microsoft.com/en-us/library/bb890248.aspx

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

So the next thing I did was, again, generating the classes for the metadata service, based on it's WSDL. The result of the generated classes are not as we except. For example, it generates a class 'com.microsoft.schemas.crm._2007.webservices.ExecuteResponse'. But this class also exists in the exact same package of the CrmService generated classes. Differences between the 2 are:

Metadataservice ExecuteReponse:

Metadataservice ExecuteReponse:

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

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

CrmService ExecuteReponse:

CrmService ExecuteReponse:

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

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

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

Now this class is just one example (another example is CrmAuthenticationToken), which is a almost exact duplicate of another class. To be able to use the same classes, I've added a package-suffix to the CrmService classes (displayed as prefix.). So now when I try to call the CrmService, I get the following exception:

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个web服务..

I personally think it's weird they put different classes with the same name in the same package structure. This means you can never use the 2 webservices at the same time..

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

Is this a Microsoft, a WSimport bug or just a stupid mistake at my end? Hope somebody can help me with this problem!

感谢您的时间!

推荐答案

这是微软的不一致与wsimport结合起来有点难以使用。

This is Microsoft inconsistency combined with wsimport being somewhat hard to use.

PickList和CRMAuthenticationToken听起来像自定义数据类型,你期望它们得到这些从服务到服务的重用。
您还希望某些特定于CRM的实体(例如,客户或业务或地址)可以从服务重用到服务。

The PickList and the CRMAuthenticationToken sound like custom datatypes, you'd expect for these to get reused from service to service. You'd also expect certain CRM-specific entities (say, Customer or Business or Address) to get reused from service to service.

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

It is bad manners on the Microsoft side of things that they define these differently for different services. This makes it hard to take the answer of one service and send it on to another service.

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

Had the services shared one or more common schemas, you could've compiled those first, using xjc. Then you could've provided a so-called episode file to wsimport to tell it to use those classes instead of generating new ones. See the metro guide. This is quite a puzzle, I can tell you from experience, I ran into bug JAXB-829, xjc forgets to generate if-exists attributes in the episode file.

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

What I'd do, I'd compile each wsdl to its own package and treat the generated classes as simple unintelligent Data Transfer Objects. If I wanted to send an object I'd just retrieved from one service on to a second service, I'd convert between the both. If this results in terribly unwieldy code, or if you wish to add logic to certain entities, I'd suggest you write your own proper model classes for the Entities you wish to share and write converters to and from the DTO objects in the web services packages you wish to use them with.

这篇关于WSImport为多个Dynamics CRM 4.0 WSDL生成冲突的XMLType的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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