Interaction when returning a derived class by base class in WCF

I have a simple code:

   [DataContract]
   [KnownType(typeof(SpecialEvent))]
   public class Event
   {
     //data
   }

   [DataContract]
   public class SpecialEvent : Event
   {
     //data
   } 

   [ServiceContract]
   public interface IService
   {
        [OperationContract]
        List<Event> GetEvents();
   }

    [ServiceBehavior]
    public class Service : IService
    {
       public List<Event> GetEvents()
       {
           List<Event> events = new  List<Event>();
           events.Add(new Event());
           events.Add(new SpecialEvent());
           return events;
       }
    }

I know that it works fine in case of wcf in wcf.

but what about interoperability?

It generates standard wsdl, and can any client use this service or not?

+3
source share
1 answer

Yes, it is compatible. I wrote a service that uses well-known types in a similar way, and some third parties call this service many clients, including Java and PHP.

EDIT: WCFExtras

, , , , WCF, WSDL WCF. , WCF WSDL , . , - WCFExtras, WSDL .

+2

Source: https://habr.com/ru/post/1743476/


All Articles