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

WCF can't serialize an interface either; in fact, it's impossible to serialize an interface over SOAP.

WCF can't serialize an interface either; in fact, it's impossible to serialize an interface over SOAP. The reason (simplified) is that, when deserializing, . NET has to be able to create some actual concrete class.An interface is an abstract concept; there always has to be a "real" class implementation behind it in order for an actual instance to exist.

Since you can't construct a physical instance of an interface, it also can't be serialized. If you're trying to use the XmlIgnoreAttribute, understand that applying it to the type won't accomplish anything.It needs to be applied to the member instead. In other words: public class SerializableClass { XmlElement public int ID { get; set; } XmlElement public string Name { get; set; } XmlIgnore public IMyInterface Intf { get; set; } } ...will serialize OK, because the serializer won't try to serialize the Intf property.

You just can't add the XmlIgnore attribute to the IMyInterface type definition (it won't compile).

Thanks for the clear explanation; it makes perfect sense. – mcliedtk Apr 5 '10 at 21:57 I was wondering if that was the case and then read the question again and though he was trying to use a class that had an interface. – Joshua Apr 6 '10 at 2:28.

Make a function AsIWigit() that returns a private bridge class that implements said interface. This will provide a way to convert these classes to the appropriate interface as needed and will work with the ASMX services.

1 nice idea for getting around this – mcliedtk Apr 5 '10 at 21:57.

Because interfaces can't be serialized. See stackoverflow.com/questions/659039/web-s....

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions