I have created an ASP.NET C# project which consists of a web form and a WebSocket handler. I would like to send 2 data (name & price data) from the web form in JSON string format to the WebSocket handler. Here is the code snippet in the web form:
ws.onopen = function()
{
var name = "Client Product";
var price = 10.8;
ws.send(JSON.stringify(name));
ws.send(JSON.stringify(price));
alert("Message is sent...");
};
In the WebSocket handler's OnMessage(string) method, I would like to retrieve the 2 data sent by the web form and deserialize the 2 data to c# format. Here is the code snippet in the WebSocket handler:
public override void OnMessage(string message)
{
string serverName="";
string serverPrice = "";
serverName = JsonConvert.DeserializeObject<string>(message);
serverPrice = JsonConvert.DeserializeObject<string>(message);
}
However, under the WebSocket handler's onMessage(string) method, both the variable serverName and serverPrice would be assigned as "Client Product". I want the variable serverPrice to be assigned as "10.8", instead of "Client Product".
Can somebody please tell me how I could achieve that? WILL really appreciate if you could help me :) Thank You :)