Search code examples
wcfservice-reference

WCF Update Service Reference Error


I'm desesperated, I'm trying to update an existing service reference to a WCF service (sharing types) and I can't. I've tryied all what I've found on Google (social.msdn, stackoverflow, ...) but I haven't found the solution to my problem.

I've have a ServiceContract and I add a new Operation like the code below:

[ServiceContract]
public partial interface IServiceDTO : IGenericServiceDTO<EntityDTO>    
{
        // Some OperationContracts working like
        [OperationContract]
        EntityDTO[] Method(int field);

        // NewMethod
        [OperationContract]
        OtherEntityDTO[] NewMethod(int field);
}

[DataContract]
public class EntityDTO {
    // Some properties working
}


[DataContract]
public class OtherEntityDTO {
    // Some properties working
    [DataMember]
    YetAnotherEntity NewProperty {get;set;}
}

When I try to update the service reference it throws me the follwing error:

Attempting to download metadata from 'http://localhost:65499/Services/Acciones/ProcesoServiceDTO.svc' using WS-Metadata Exchange or DISCO. Error: Cannot import wsdl:portType Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.DataContractSerializerMessageContractImporter Error: Referenced type 'mpm.seg.ServiceModel.DTO.DataContracts.Acciones.ProcesoDTO, mpm.seg.ServiceModel.DTO.DataContracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' with data contract name 'ProcesoDTO' in namespace 'http://schemas.datacontract.org/2004/07/mpm.seg.ServiceModel.DTO.DataContracts.Acciones' cannot be used since it does not match imported DataContract. Need to exclude this type from referenced types.XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:portType[@name='IProcesoServiceDTO']

First of all, I don't understand exactly the sentence "...cannot be used since it does not match imported DataContract." How the svcutil is trying to match referenced type to imported DataContract? I've referenced the project that have the referenced types on the client project, cause server and client are in the same solution, but I've tried to separate them and reference exactly the same dll too.

Also, when I try, for example, the following situation it works (write "NewProperty" of the "OtherEntityDTO to EntityDTO"), and I don't understand the difference:

[ServiceContract]
public partial interface IServiceDTO : IGenericServiceDTO<EntityDTO>    
{
        // Some OperationContracts working like
        [OperationContract]
        EntityDTO[] Method(int field);

        // NewMethod
        [OperationContract]
        OtherEntityDTO[] NewMethod(int field);
}

[DataContract]
public class EntityDTO {
    // Some properties working

    [DataMember]
    YetAnotherEntity NewProperty {get;set;}

}


[DataContract]
public class OtherEntityDTO {
    // Some properties working
}

Please, help me and thanks a lot in advance.


Solution

  • Sorry, but after I've posted the question I've found the problem and it was a reported bug (http://blogs.msdn.com/b/distributedservices/archive/2010/02/04/wcf-client-issue-with-reuse-types-from-referenced-assemblies.aspx?wa=wsignin1.0). Another developer had added this attribute (IsReference=true) on a parent class and I didn't know. Now I must to workaround this bug, but that's another battle.

    Anyway, I don't understand why sometimes work and sometimes not...

    Thanks.