My service implements a method that returns an custom object called WebServiceResult. One of the object properties (.Items) is of a IList type.
Depending on the instantiated business object type (I am using a class factory) it returns List<TheSuitableResultType>. The service works, however when it's getting called from WCF client it fails with the
System.ServiceModel.CommunicationException internal error:
The type [TheSuitableResultType] was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically.
It took me few hours to work out that I should actually do what the error tells me :-|
Because the service returns IList it's not able to work out how to serialize the contents of the list. I needed to decorate the WebServiceResult with all possible types that can be returned
[XmlInclude(typeof(SuitableResultType1))]
[XmlInclude(typeof(SuitableResultType2))]
[XmlInclude(typeof(SuitableResultType3))]
public class WebServiceResult {
etc...