문제

I am having problems creating WCF client proxy for service code like in this example:

// data classes
[KnownType(typeof(ClassA))]
[KnownType(typeof(ClassB))]
public abstract class BaseClass : Dictionary<string, ITest>
{
}

public class ClassA : BaseClass
{
}

public class ClassB : BaseClass
{
}


public interface ITest
{
}

// service
[ServiceContract]
public interface IService1
{
    [OperationContract]
    BaseClass Method();
}

public class Service1 : IService1
{
    public BaseClass Method()
    {
        ...
    }
}

Whenever I try to create a WCF proxy using "Add Service Reference" in VS it fails and trace log says

Type 'WcfProxyTest.ClassA' cannot be added to list of known types since another type 'WcfProxyTest.ClassB' with the same data contract name 'http://schemas.microsoft.com/2003/10/Serialization/Arrays:ArrayOfKeyValueOfstringanyType' is already present. If there are different collections of a particular type - for example, List<Test> and Test[], they cannot both be added as known types. Consider specifying only one of these types for addition to the known types list.

I can see what the error message is saying, but is there any other way around this (other than refactoring the classes). I am dealing with a legacy system which has classes written in the same manner as in my example and rewriting them is not an option as this stuff sits in the very core of the system :S

Any ideas? Thanks!

도움이 되었습니까?

해결책

I decided to refactor the code in such a way that I don't have to provide two KnownTypes which gets me around the problem. About 300 syntax errors later that worked. I would be interested in any other ways of doing it though...

다른 팁

Try adding:

[KnownType(typeof(Dictionary<string, ITest>))]
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top