Hello,

I currently have a sample WCF service that has the following classes:

using System;

namespace SampleWCFService
{
    [Serializable]
    public class BaseClass
    {
        public string someText;

        public BaseClass(string someText)
        {
            this.someText = someText;
        }
    }
}

using System;

namespace SampleWCFService
{
    [Serializable]
    public class ExtendedClass : BaseClass
    {
        public int someNumber;

        public ExtendedClass(string someText, int someNumber): base(someText)
        {
            this.someNumber = someNumber;
        }
    }
}

Here is the contract I am currently using (that works):

using System.ServiceModel;

namespace SampleWCFService
{
    [ServiceContract]
    public interface IService
    {
        [OperationContract(Name = "testPoly")]
        ExtendedClass testPoly();
    }
}

using System;
using System.ServiceModel.Activation;

namespace SampleWCFService
{
    public class Service : IService
    {
        public ExtendedClass testPoly()
        {
            return new ExtendedClass("extended class", 100);
        }
    }
}

For the record, I'm running a simple program the hosts the SampleWCFService using httpBinding, and I have another program that creates a client using a ServiceReference from the hosted SampleWCFService:

using TestWCFService.SampleWCFService;

namespace TestWCFService
{
    class Program
    {
        static void Main(string[] args)
        {
            ServiceClient client = new ServiceClient();
            ExtendedClass extendedClass = client.testPoly();
        }
    }
}

This works fine. However, if I alter the OperationContract to return a BaseClass object while returning an ExtendedClass object (polymorphism), my call bombs (and I have debugged the SampleWCFService and nothing bad happens within the code) . [Note: changing the OperationContract to return a BaseClass object while returning a BaseClass DOES work]

(changes that fail)

using System.ServiceModel;

namespace SampleWCFService
{
    [ServiceContract]
    public interface IService
    {
        [OperationContract(Name = "testPoly")]
        BaseClass testPoly();
    }
}

using System;
using System.ServiceModel.Activation;

namespace SampleWCFService
{
    public class Service : IService
    {
        public BaseClass testPoly()
        {
            // polymorphism
            return new ExtendedClass("extended class", 100);
        }
    }
}

Any ideas why polymorphism fails in this situation and what I can do about it? I've also tried running a test program that serializes these same classes to a file in SOAP format and then reads it back again and that seemed to work.

This is also the exception I am getting back from the client:

An error occurred while receiving the HTTP response to http://localhost:8080/Service. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.

Thanks for your help.

Ed

This question has already been answered. Start a new discussion instead.