WCF错误:需要排除以下类型之一以外的所有类型.仅匹配类型可以是有效引用 [英] WCF error: Need to exclude all but one of the following types. Only matching types can be valid references
问题描述
我在WCF服务中遇到此错误.这是我使用Microsoft Service Trace Viewer查看错误详细信息时得到的错误报告:
I'm getting this error with a WCF service. This is the error report I get when I use the Microsoft Service Trace Viewer to view the error details:
运行WSDL导入扩展时引发了异常:System.ServiceModel.Description.DataContractSerializerMessageContractImporter错误:引用类型的列表在名称空间' http://schemas.datacontract.org/2004/07/WorldVision.NewZealand.CIMS.Common.Entities ".需要排除以下类型之一以外的所有类型.只有匹配类型可以是有效的引用:"CIMS.CrmService.EchoAddress,App_WebReferences.k4hj-nad,版本= 0.0.0.0,区域性=中性,PublicKeyToken =空"(匹配)"CIMS.AddressService.EchoAddress,App_WebReferences.k4hj-nad,Version = 0.0.0.0,Culture = neutral,PublicKeyToken = null"(匹配)
An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.DataContractSerializerMessageContractImporter Error: List of referenced types contains more than one type with data contract name 'EchoAddress' in namespace 'http://schemas.datacontract.org/2004/07/WorldVision.NewZealand.CIMS.Common.Entities'. Need to exclude all but one of the following types. Only matching types can be valid references: "CIMS.CrmService.EchoAddress, App_WebReferences.k4hj-nad, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" (matching) "CIMS.AddressService.EchoAddress, App_WebReferences.k4hj-nad, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" (matching)
它看起来就像有两个名为"EchoAddress"的单独类,我已经使用[DataContract]属性定义为WCF DataContracts,它们都存在于WorldVision.NewZealand.CIMS.Common.Entities命名空间中.我已经检查过了,事实并非如此.该错误还表示我需要排除以下类型之一:
It reads like there are two separate classes called 'EchoAddress' that I've defined as WCF DataContracts using the [DataContract] attribute, that both exist in the WorldVision.NewZealand.CIMS.Common.Entities namespace. I've checked and this isn't the case. The error also says I need to exclude one of the following types:
CIMS.CrmService.EchoAddressCIMS.AddressService.EchoAddress
CIMS.CrmService.EchoAddress CIMS.AddressService.EchoAddress
但是我只在WorldVision.NewZealand.CIMS.Common.Entities命名空间中声明了'EchoAddress'类一次.看起来这些是在"CrmService"和"AddressService"中对相同类型(EchoAddress)的引用,它们是我从主项目中引用为服务引用"的两个单独的WCF服务.
But I only declare the 'EchoAddress' class once, in the WorldVision.NewZealand.CIMS.Common.Entities namespace. It looks like these are references to the same type (EchoAddress), within both the 'CrmService' and 'AddressService', which are two separate WCF services that I'm referencing as 'service references' from my main project.
这是EchoAddress类的类型声明,它在一个单独的项目中声明,然后由包含实际WCF服务的项目引用.然后,我的主项目将服务引用为服务引用:
This is the type declaration for the EchoAddress class, which is declared in a separate project that then gets referenced by the project that contains the actual WCF services. My main project then references the service as a service reference:
[DataContract]
public class EchoAddress
{
[DataMember]
public string AddressType { get; set; }
[DataMember]
public Dictionary<string,string> AddressLines { get; set; }
...
}
我尝试了以下操作:
- 在VS2010中,右键单击WCF服务参考>配置服务参考>从Web服务参考配置的高级"菜单中为CrmService和AddressService WCF服务取消选中在参考程序集中重用类型".
- 删除了Web服务引用,关闭了VS2010,使用以管理员身份运行"打开VS2010,重新添加了Web服务引用.
- 在整个解决方案中搜索了对EchoAddress的重复引用
- 为所有数据类型设置[DataContract(IsReference = false)],如下所示:
- 尝试更新服务参考,重建单个项目,整个解决方案以及您能想到的每种组合!
- 尝试逐步进入调试器-没有提供更多信息,只是在尝试通过WCF服务使用MS Dynamics CRM API中的OrganizationServiceContext.SaveChanges()写入CRM时失败
- 已阅读以下内容:
- http://社交.msdn.microsoft.com/Forums/zh-CN/wcf/thread/6ab067fe-0607-4b6e-8ab7-a5e2db1dd490
- 此WCF错误是什么意思是:自定义工具警告:无法导入wsdl:portType"
- http://www.lukepuplett.com/2010/07/note-to-self-don-let-wcf-svcutil-reuse.html
- 并且即将完成阅读:
- 有什么想法吗?
推荐答案
由于诸如此类的各种隐秘问题,当我们的服务复杂性增加时,我们完全放弃了添加服务引用方法.原因是缺乏控制力,幸灾乐祸和错误.如果您主要使用的是.net world的服务,请观看以下视频
Dueto various cryptic problems like this when our service complexity grew we moved away from the add service reference method completely. The reason was lack of control , gloat and errors. If you are primarily using the service from .net world then watch the following video
http://www.dnrtv.com/default.aspx?showNum=122
这还将为您提供许多内部信息,并帮助调试wcf问题.一旦采取行动,您将永远不会回来!
This will also give you a lot of internals info and help debug wcf issues. Once you make the move you will never come back!
这篇关于WCF错误:需要排除以下类型之一以外的所有类型.仅匹配类型可以是有效引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!