private static HttpContent CreateMessageContent(Message message, bool suppressEntityBody) { Fx.Assert(message != null, "The 'message' parameter should not be null."); if (suppressEntityBody || message.IsEmpty) { return(new ByteArrayContent(EmptyArray <byte> .Instance)); } return(new StreamContent(message.GetBody <Stream>())); }
private string PeekAndRetrieveMessage(MessageBufferClient client) { System.ServiceModel.Channels.Message lockedMessage = client.PeekLock(); try { client.DeleteLockedMessage(lockedMessage); return(lockedMessage.GetBody <string>()); } finally { if (lockedMessage != null) { lockedMessage.Close(); } } }
public Stream GetResponseMessageStream(Message message) { if (message == null) { throw FxTrace.Exception.ArgumentNull("message"); } ThrowIfMismatchedMessageVersion(message); if (!ByteStreamMessage.IsInternalByteStreamMessage(message)) { return(null); } return(message.GetBody <Stream>()); }
private string RetrieveMessage(MessageBufferClient client) { System.ServiceModel.Channels.Message retrievedMessage = null;; try { retrievedMessage = client.Retrieve(); return(retrievedMessage.GetBody <string>()); } finally { if (retrievedMessage != null) { retrievedMessage.Close(); } } }
public async Task SendMessageToServer(System.ServiceModel.Channels.Message msg) { if (msg.IsEmpty) { Console.WriteLine("received empty message"); return; } byte[] body = msg.GetBody <byte[]>(); string clientMessage = Encoding.UTF8.GetString(body); JObject jsonMessage = JObject.Parse(clientMessage); string type = jsonMessage["type"].ToString(); JToken data = jsonMessage["data"]; switch (type) { case Message: await chatService.SendMessage(data); break; case FriendshipRequest: await friendService.AddFriend(data); break; case FriendshipAccept: await friendService.ReplyToFriendRequest(data); break; case Login: IWebsocketCallback webCallback = OperationContext.Current.GetCallbackChannel <IWebsocketCallback>(); await loginService.Subscribe(data, webCallback); break; default: Console.WriteLine(String.Format("{0} type is not supported", type)); break; } }