我目前正在使用 Dynamics CRM 4.0 Web 服务。我做的第一件事是使用 wsimport 生成正确的类Java/JAX-WS
基于 Web 服务的 WSDL。在生成类时我遇到了一些错误:
[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 服务的调用,这太棒了!
现在问题来了:dynamics crm中的一些业务实体使用了该类Picklist。可以使用元数据服务查询此类实体:http://msdn.microsoft.com/en-us/library/bb890248.aspx http://msdn.microsoft.com/en-us/library/bb890248.aspx
因此,我接下来要做的就是根据元数据服务的 WSDL 生成元数据服务的类。生成的类的结果与我们不同。例如,它生成一个类“com.microsoft.schemas.crm._2007.webservices.ExecuteResponse”。但该类也存在于 CrmService 生成的类的完全相同的包中。 2者之间的区别是:
元数据服务执行响应:
@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...
现在这个类只是一个例子(另一个例子是Crm身份验证令牌),这是一个almost另一个类的精确副本。为了能够使用相同的类,我向 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 个网络服务。
这是 Microsoft、WSimport 错误还是只是我的一个愚蠢错误?希望有人能帮助我解决这个问题!
谢谢你的时间!