public Message SerializeReply(MessageVersion messageVersion, object[] parameters, object result) { byte[] body; var serializer = NewtonsoftJsonSettings.GetSerializer(); using (var ms = new MemoryStream()) { using (var sw = new StreamWriter(ms)) { using (Newtonsoft.Json.JsonWriter writer = new Newtonsoft.Json.JsonTextWriter(sw)) { writer.Formatting = NewtonsoftJsonSettings.GetFormatting(); serializer.Serialize(writer, result); sw.Flush(); body = ms.ToArray(); } } } var respProp = new HttpResponseMessageProperty(); respProp.Headers[HttpResponseHeader.ContentType] = "application/json"; var replyMessage = Message.CreateMessage(messageVersion, m_operation.Messages[1].Action, new RawBodyWriter(body)); replyMessage.Properties.Add(WebBodyFormatMessageProperty.Name, new WebBodyFormatMessageProperty(WebContentFormat.Raw)); replyMessage.Properties.Add(HttpResponseMessageProperty.Name, respProp); return(replyMessage); }
public Message SerializeRequest(MessageVersion messageVersion, object[] parameters) { byte[] body; var serializer = NewtonsoftJsonSettings.GetSerializer(); using (var ms = new MemoryStream()) { using (var sw = new StreamWriter(ms)) { using (Newtonsoft.Json.JsonWriter writer = new Newtonsoft.Json.JsonTextWriter(sw)) { writer.Formatting = NewtonsoftJsonSettings.GetFormatting(); if (parameters.Length == 1) { // Single parameter, assuming bare serializer.Serialize(sw, parameters[0]); } else { writer.WriteStartObject(); foreach (MessagePartDescription t in this.m_operation.Messages[0].Body.Parts) { writer.WritePropertyName(t.Name); serializer.Serialize(writer, parameters[0]); } writer.WriteEndObject(); } writer.Flush(); sw.Flush(); body = ms.ToArray(); } } } Message requestMessage = Message.CreateMessage(messageVersion, m_operation.Messages[0].Action, new RawBodyWriter(body)); requestMessage.Headers.To = m_operationUri; requestMessage.Properties.Add(WebBodyFormatMessageProperty.Name, new WebBodyFormatMessageProperty(WebContentFormat.Raw)); HttpRequestMessageProperty reqProp = new HttpRequestMessageProperty(); reqProp.Headers[HttpRequestHeader.ContentType] = "application/json"; requestMessage.Properties.Add(HttpRequestMessageProperty.Name, reqProp); return(requestMessage); }