WCF contract returning interface could cause serialization issue?

前端 未结 2 909
滥情空心
滥情空心 2020-12-15 13:06

I am trying to define a WCF contract that returns an interface, something like below:

[ServiceContract]
public interface IMyContracts
{
    [OperationContrac         


        
2条回答
  •  粉色の甜心
    2020-12-15 13:14

    AFAIK, the problem is not with serialization but with the fact that you're returning abstract entity (an interface). Abstraction is an OO concept, not SOA concept. So, your client's wcf stack may not know what to do with the class behind the interface. What if the client does not know the class behind the interface. Client's WCF stack must deserialize it, and to do it, it must know the class.

    So, you must make the class(es) behind the interface part of your contract, via KnownTypeAttribute.

    You may also use ServiceKnownTypeAttribute class that seems to be more flexible. Still, remember that the client must know the type, or you'll get an exception.

提交回复
热议问题