Ogólne typy powrotu z parametrami typu interfejsu w WCF

Jak mogę zwracać typy interfejsów w ogólnych parametrach typu zOperationContracts w mojej usłudze REST WCF? Dokładniej, działa dla jednej operacji, ale nie, gdy dodam drugą operację za pomocą generycznegoT to jest interfejs.

Używam JSON jako formatu żądania i odpowiedzi, zasilając klienta innego niż WCF, który analizuje odpowiedzi JSON dla potrzebnych danych. Nie używam SOAP ani WSDL generowanego przez usługę.

Mój interfejs usługi:

[ServiceContract]
[ServiceKnownType("GetServiceKnownTypes", typeof(ServiceKnownTypesHelper))]
public interface IMyService
{
    [WebGet(UriTemplate="count")]
    [OperationContract]
    IServiceResult<int> GetCount();

    [WebGet(UriTemplate="desc")]
    [OperationContract]
    IServiceResult<string> GetDescription();

    [WebGet(UriTemplate="foo")]
    [OperationContract]
    IServiceResult<IFooData> GetFooData();

    // Fails when I invoke either method if I uncomment this operation.
    //[WebGet(UriTemplate="bar")]
    //[OperationContract]
    //IServiceResult<IBarData> GetBarData();
}

wyszedłemGetCount() iGetDescription() w przykładzie, aby podkreślić, że te dwa ogólne wyniki działają dobrze, ale oczywiście są to konkretne typy. I nawetGetFooData() działa dobrze, dopóki nie dodam drugiej metodyIServiceResult<T> gdzieT jest interfejsem.

Typy powrotuGetFooData() iGetBarData() nie są takie same, ani konkretne klasy, które je realizują.

Możesz sobie wyobrazić, że zredukowałem implementację do szkieletu, ponieważ nie sądzę, aby implementacja była sercem problemu:

#region My service implementation
public class MyService : IMyService
{
    public IServiceResult<int> GetCount()
    {
        return new ServiceResult<int>(42);
    }
    public IServiceResult<string> GetDescription()
    {
        return new ServiceResult<string>("Muffins");
    }
    public IServiceResult<IFooData> GetFooData()
    {
        return new ServiceResult<IFooData>(new FooData() { Foo = 99 });
    }
    public IServiceResult<IBarData> GetBarData()
    {
        return new ServiceResult<IBarData>(new BarData() { Bar = "Elvis was here" });
    }
}
#endregion

#region ServiceKnownTypesHelper.GetServiceKnownTypes():
public static class ServiceKnownTypesHelper
{
    private static IList<Type> serviceKnownTypes = new List<Type>()
        {
            typeof(FooData),
            typeof(BarData),
            typeof(ServiceResult<int>),
            typeof(ServiceResult<string>),
            typeof(ServiceResult<IFooData>),
            typeof(ServiceResult<IBarData>),
        };

    public static IEnumerable<Type> GetServiceKnownTypes(ICustomAttributeProvider paramIgnored)
    {
        return serviceKnownTypes;
    }
}
#endregion

#region IServiceResult<T> and its concrete implementation:
public interface IServiceResult<T>
{
    IList<string> Errors { get; }
    T Value { get; set; }
}

[DataContract]
public class ServiceResult<T> : IServiceResult<T>
{
    public ServiceResult(T value)
    {
        this.Value = value;
    }

    private IList<string> errors = new List<string>();

    [DataMember]
    public IList<string> Errors
    {
        get
        {
            return this.errors;
        }
    }

    [DataMember]
    public T Value { get; set; }
}
#endregion

#region IFooData and its concrete implementation:
public interface IFooData
{
    int Foo { get; set; }
}

[DataContract]
public class FooData: IFooData
{
    [DataMember]
    public int Foo { get; set; }
}
#endregion

#region IBarData and its concrete implementation:
public interface IBarData
{
    string Bar { get; set; }
}

[DataContract]
public class BarData: IBarData
{
    [DataMember]
    public string Bar { get; set; }
}
#endregion

I komunikat o błędzie, kiedy wywołujęGetBarData() z przeglądarki:

Type 'ServiceResult`1[IBarData]' cannot be added to list of known types since
another type 'ServiceResult`1[IFooData]' with the same data contract name
'http://schemas.datacontract.org/2004/07/ServiceResultOfanyType' is
already present. 

Pozostała część komunikatu o błędzie to czerwony śledź o kolidujących typach kolekcjiList<Test> iTest[], co nie ma tu miejsca.

Wyraźnie,IFooData iIBarData nie są takie same, ani klasy, które je realizują.

Więc dlaczegoServiceResult<IFooData> iServiceResult<IBarData> obie postanawiająServiceResultOfanyType?

Czy czegoś mi brakuje, czy nie ma sposobu, aby to naprawić?

questionAnswers(1)

yourAnswerToTheQuestion