WCF MessageContract Inheritance

I am new to WCF and just wondering how to properly get MessageContract inheritance. A simplified version of my setup looks like this: the "base" type of message, and then another "test" message that inherits from it.

[MessageContract]
public abstract class BaseMessage
{ }

[MessageContract]
public class TestMessage : BaseMessage
{ }

Then I have an asynchronous OperationContract in a ServiceContract, which is defined as:

[OperationContract(AsyncPattern = true)]
IAsyncResult BeginFindRequest(BaseMessage request, AsyncCallback callback, object asyncState);

The problem that occurs when calling the BeginFindRequest method and passing the TestMessage instance for the request parameter, WCF deserializes the TestMessage instance for BaseMessage on the service / server side. Since this is defined as an abstract class, this leads to the following error:

"A message cannot be deserialized to the MessageContract BaseMessage type because it does not have a default value (no parameters).

, MessageContract, , .

, : , ? OperationContract ServiceContract - , OperationContracts?

+5
5

, -

, WCF, , : , . : " ? XML?". XML , , XML. , .NET XML - , . , - DataContracts .

http://www.dotnetconsult.co.uk/weblog2/PermaLink,guid,a3775eb1-b441-43ad-b9f1-e4aaba404235.aspx

, . , .

.

+6

, : ? ?

, SOAP, . , , ..

"" WCF - .

( ) [ServiceContract], [DataContract]. DataContract, , / (, ).

+3

BaseMessage , ?

, BaseMessage, .

0

, , . marc_s; , , , , , , messasges.

0

[ServiceContract] KnownType. TestMessage , , , .

If this should allow serialization [DataContract]as TestMessage , you still have to process multiple messages differently through ` is a` or some other casting.

0
source

All Articles