WCF error: Need to exclude all but one of the foll

2019-08-03 05:04发布

问题:

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:

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)

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.EchoAddress CIMS.AddressService.EchoAddress

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.

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; }

    ...
}

I've tried the following:

  • In VS2010, right-click the WCF service reference > configure service reference > unchecked 'Reuse types in reference assemblies from the Advanced menu of the webservice reference configuration, for both the CrmService and AddressService WCF services.
  • Removed web service references, closed down VS2010, opened VS2010 with 'run as adminstrator', re-added web service references.
  • Searched entire solution for duplicate references to EchoAddress
  • Set [DataContract(IsReference = false)] for all data types, as per: http://blogs.msdn.com/b/distributedservices/archive/2010/02/04/wcf-client-issue-with-reuse-types-from-referenced-assemblies.aspx
  • Checked that there are no class members anywhere marked with [DataMember] that are also called EchoAddress' (apparently this error can occur when this type of structure exists - see the above link for details)
  • Checked all project references, to ensure there are no 'circular' type references (e.g. project 1 references project 2, project 1 has service reference to service1, project 2 also has service reference to service1. Have checked for service references, project references and 'standard' dll references that could have caused this.
  • Tried updating the service references, rebuilding individual projects, entire solution, every combination you can think of!
  • Tried stepping through in the debugger - doesn't give any more info, just fails at the point where I'm trying to write into our CRM via the WCF service, using OrganizationServiceContext.SaveChanges() from the MS Dynamics CRM API
    • Have read these:
    • http://social.msdn.microsoft.com/Forums/en/wcf/thread/6ab067fe-0607-4b6e-8ab7-a5e2db1dd490
    • What does this WCF error mean: "Custom tool warning: Cannot import wsdl:portType"
    • http://www.lukepuplett.com/2010/07/note-to-self-don-let-wcf-svcutil-reuse.html
    • and am just about finished reading:
    • http://marktinderholt.wordpress.com/2010/02/12/silverlight-wcf-service-reference-weirdness-solved-custom-tool-error-failed-to-generate-code-for-the-service-reference-%E2%80%98servicereference1%E2%80%99-please-check-other-error-and-warnin/

Any ideas?

回答1:

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

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!