user3452883
user3452883

Reputation: 65

DataContractJsonSerializer with NetworkStream

i want to use the DataContractJsonSerializer class in combination with the TcpClient to receive and send JSON serialized objects. I am able to send JSON serialized objects but the receiving part does not work.

Source code of sending objects:

IPEndPoint endPoint = new IPEndPoint(IPAddress.Loopback, tcpPort);
TcpClient tcpClient = new TcpClient();
tcpClient.Connect(endPoint);
var ser = new DataContractJsonSerializer(typeof(....));
 ser.WriteObject(tcpClient.GetStream(), req);

Source code of receiving objects:

var deser = new DataContractJsonSerializer(typeof(...));
var resp = (....)deser.ReadObject(tcpClient.GetStream());

The method ReadObject is hanging. Can anyone tell me the issue and how I can solve it? Thanks in advance.

Best regards

Upvotes: 0

Views: 140

Answers (0)

Related Questions