I have created an application where interprocess communication is done using sockets. The procedure starts when a client connects with the server that I created and sends a serialized message. This message, I serialize using Protobuf-net, using SerializeWithLengthPrefix and deserialize it using DeserializeWithLengthPrefix. The client sends messages to the server who deserializes it perfectly, but the same is not true in the case of server to client.
The main class is BaseMessage, which is abstract.
[Serializable, ProtoContract, ProtoInclude(5001, typeof(LogonMessage))]
abstract public class BaseMessage
{
public BaseMessage()
{
}
abstract public int MessageType { get; }
}
And LogonMessage implements the BaseMessage Class.
[Serializable, ProtoContract]
public class LogonMessage : BaseMessage
{
public LogonMessage()
{
}
[ProtoMember(1)]
public string Broker { get; set; }
[ProtoMember(2)]
public int ClientType { get; set; }
public override int MessageType
{
get { return 1; }
}
}
After the initial handshake, the client requests some service serialized with the help of protobuf-net and the local server at my end serves it by requesting data from another server on the web. This message transfer from the client to the server is done flawlessly.
When my server receives the data from the web server, it serializes it and sends the data to the client. But this time, when I try to deserialize the data on the client-side using the same procedure, I get the following exception: "No parameterless Constructor found for BaseMessage"
I deserialize using the following line of code(this is where the exception occurs).
BaseMessage baseMessage = Serializer.DeserializeWithLengthPrefix<BaseMessage>(networkStream, PrefixStyle.Base128);
And this is how the message was serialized on the server.
Serializer.SerializeWithLengthPrefix(networkStream, baseMessage, PrefixStyle.Base128);
The NetworkStream used at the start of the connection between the client and server is stored in an object and that object is stored in a dictionary. I pick out the same NetworkStream from that object in the dictionary and use it to send serialized data to the client(from the server). But the above mentioned problem occurs. Any help?
Thanks in advance...