Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Interoperability when returning derived class by base class in WCF

I have some 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 wcf to wcf.

but what about interoperability?

is it generate standart wsdl and any client can use the service or no?

like image 268
mt_serg Avatar asked Jul 04 '26 02:07

mt_serg


1 Answers

Yes, this is interoperable. I have written a service that uses Known Types in a similar way and several third parties are calling that service from a variety of clients, including Java and PHP.

EDIT: WCFExtras

One thing I've learned is that not all non-WCF clients can understand WCF's default WSDL. The problem is that WCF splits its WSDL into several parts rather than using a single file. You can fix this by using something like WCFExtras to merge the WSDL back into a single file.

  • http://wcfextras.codeplex.com/
like image 95
Damian Powell Avatar answered Jul 06 '26 19:07

Damian Powell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!