webservice

  • Thread starter Thread starter Peter K
  • Start date Start date
P

Peter K

Hi

I have an existing code-base with some functions which are used by a web
application (aspx and ascx).

Now I want to add a web-service front to these functions, so they are
available via webservice calls.

The problem I am running into is that the functions in the existing
codebase have return values which are interfaces, and when I try to consume
the webservice I get exceptions like: Cannot serialize interface
Alpha.Access.IAnnounce".

How do I work around this? Do I need to provide my own concrete
implementations of all the various interfaces used by the various
functions, and return/convert them via my webservice? This could be very
tedious and difficult in light of that many of these interfaces in turn
contain methods with other interfaces...


Thanks,
Peter
 
Hi,

take a look at System.Xml.Serialization.XmlIncludeAttribute.

Using this you only have to refactor your interfaces to abstract
classes (interfaces are not serializable).

Example:

You have an interface IInterface with implementaions ImplA and ImplB.

After refactoring you hav an abstract class AbstractClass with derived
classes ImplA and ImplB.

For the AbstractClass class apply the XmlIncludeAttribute as follows:

[XmlInclude(typeof(ImplA)), XmlInclude(typeof(ImplB))]
public abstract class AbstractClass {...}
 
take a look at System.Xml.Serialization.XmlIncludeAttribute.

Using this you only have to refactor your interfaces to abstract
classes (interfaces are not serializable).

Example:

You have an interface IInterface with implementaions ImplA and ImplB.

After refactoring you hav an abstract class AbstractClass with derived
classes ImplA and ImplB.

For the AbstractClass class apply the XmlIncludeAttribute as follows:

[XmlInclude(typeof(ImplA)), XmlInclude(typeof(ImplB))]
public abstract class AbstractClass {...}

Thanks for the pointers. Unfortunately as this requires changes to the
existing code-base it is not possible for me. I may not change this, only
add a new "front" to the functionality (that is, a webservice).

Thanks,
Peter
 
Back
Top