static void Main(string[] args) { PostProductModel postProductModel = new PostProductModel { // generating new user id for every iteration ProductId = 701, Quantity = 100 }; string url = "ws://127.0.0.1:3251/PublicGatewayWS"; IWsSerializer serializer = SerializerFactory.CreateSerializer(); byte[] payload = serializer.SerializeAsync(postProductModel).Result; WsRequestMessage mreq = new WsRequestMessage { PartitionKey = 701, Operation = "additem", Value = payload }; using (PublicGatewayWebSocketClient websocketClient = new PublicGatewayWebSocketClient()) { var b = websocketClient.ConnectAsync(url).Result; for (int i = 0; i < 3; i++) { WsResponseMessage mresp = websocketClient.SendReceiveAsync(mreq, CancellationToken.None).Result; PostProductModel result = serializer.DeserializeAsync <PostProductModel>(mresp.Value).Result; } } Console.ReadKey(); }
/// <summary> /// Re-uses the open websocket connection (assumes one is already created/connected) /// </summary> public async Task <WsResponseMessage> SendReceiveAsync(WsRequestMessage msgspec, CancellationToken cancellationToken) { if (this.websocketManager == null) { throw new ApplicationException("SendReceiveAsync requires an open websocket client"); } // Serialize Msg payload IWsSerializer mserializer = new ProtobufWsSerializer(); byte[] request = await mserializer.SerializeAsync(msgspec); byte[] response = await this.websocketManager.SendReceiveAsync(request); return(await mserializer.DeserializeAsync <WsResponseMessage>(response)); }