Why can't I expose an interface in a .NET asmx web service?

Posted by mcliedtk on Stack Overflow See other posts from Stack Overflow or by mcliedtk
Published on 2010-04-05T21:40:30Z Indexed on 2010/04/05 21:43 UTC
Read the original article Hit count: 240

Filed under:
|
|
|
|

I have a .NET web service (using asmx...have not upgraded to WCF yet) that exposes the following:

public class WidgetVersion1 : IWidget {}
public class WidgetVersion2 : IWidget {}

When I attempt to bind to the web service, I get the following serialization error:

Cannot serialize member WidgetVersion1 of type IWidget because it is an interface.

I have tried adding various attributes to the IWidget interface (XmlIgnore, SoapIgnore, NonSerialized), but they are not valid on an interface.

Does anyone know why I am unable to expose the interface? I assume WSDL does not support interfaces, but couldn't .NET get around this by simply not serializing the interface? Are there any ways around this apart from removing the IWidget interface from the WidgetVersion1 and WidgetVersion2 class definitions?

© Stack Overflow or respective owner

Related posts about .NET

Related posts about web-services