// It is imported from samples/typed-message-converter. public void StandardToMessage() { TypedMessageConverter c = TypedMessageConverter.Create( typeof(Test1), "http://tempuri.org/MyTest"); Message msg = c.ToMessage(new Test1()); XmlDocument doc = new XmlDocument(); doc.LoadXml(msg.ToString()); XmlNamespaceManager nss = new XmlNamespaceManager(doc.NameTable); nss.AddNamespace("s", "http://www.w3.org/2003/05/soap-envelope"); nss.AddNamespace("t", "http://tempuri.org/"); nss.AddNamespace("v", "space"); nss.AddNamespace("w", "yy1"); XmlElement el = doc.SelectSingleNode("/s:Envelope/s:Body/v:MyName", nss) as XmlElement; Assert.IsNotNull(el, "#1"); XmlNode part = el.SelectSingleNode("t:body2", nss); Assert.IsNotNull(part, "#2"); Assert.AreEqual("TEST body", part.InnerText, "#3"); Assert.IsNotNull(el.SelectSingleNode("w:xx1", nss), "#4"); part = el.SelectSingleNode("w:xx1/v:msg", nss); Assert.IsNotNull(part, "#5"); Assert.AreEqual("default", part.InnerText, "#6"); }
private void HttpGetResponseThread() { try { // List<IAsyncResult> results = new List<IAsyncResult>(); bool isEOM = false; // ProcessResponseDelegate p = ProcessResponses; int responseCount = 0; // while (!isEOM) // { SessionBase.TraceSource.TraceInformation("Begin PullResponse : count {0} : clientId {1}", this.count, this.clientId); BrokerResponseMessages responseMessages = this.controller.PullResponses(this.action, this.resetToBegin, this.count, this.clientId); SessionBase.TraceSource.TraceInformation("End PullResponse : count {0} : isEOM {1}", responseMessages.SOAPMessage.Length, responseMessages.EOM); // responseCount += responseMessages.SOAPMessage.Length; responseCount = responseMessages.SOAPMessage.Length; // results.Add(p.BeginInvoke(responseMessages, clientData, null, null)); this.ProcessResponses(responseMessages, this.clientData); Interlocked.Add(ref this.responseClient.totalResponseCount, responseCount); isEOM = responseMessages.EOM; if (isEOM) { // construct endofreponses message TypedMessageConverter converter = TypedMessageConverter.Create(typeof(EndOfResponses), Constant.EndOfMessageAction); EndOfResponses endOfResponses = new EndOfResponses(); endOfResponses.Count = this.responseClient.totalResponseCount; endOfResponses.Reason = EndOfResponsesReason.Success; Message eom = converter.ToMessage(endOfResponses, MessageVersion.Soap11); eom.Headers.Add(MessageHeader.CreateHeader(Constant.ResponseCallbackIdHeaderName, Constant.ResponseCallbackIdHeaderNS, this.clientData)); this.callback.SendResponse(eom); } } catch (Exception e) { SessionBase.TraceSource.TraceInformation("PullResponse Exception: {0}", e.ToString()); if (this.disposeFlag) { return; } Message exceptionMessage = Message.CreateMessage(MessageVersion.Soap11, @"http://hpc.microsoft.com/ClientSideExeption"); exceptionMessage.Headers.Add(MessageHeader.CreateHeader(Constant.ResponseCallbackIdHeaderName, Constant.ResponseCallbackIdHeaderNS, this.clientData)); exceptionMessage.Properties.Add(@"HttpClientException", e); this.callback.SendResponse(exceptionMessage); } finally { if (this.Completed != null) { this.Completed(this, EventArgs.Empty); } } }
public Message Get(Message request) { MetadataMessage metadataMessage = new MetadataMessage(this.Metadata); string action = "http://schemas.xmlsoap.org/ws/2004/09/transfer/GetResponse"; TypedMessageConverter converter = TypedMessageConverter.Create(typeof(MetadataMessage), action); return(converter.ToMessage(metadataMessage, request.Version)); }
public static void GenerateMessage <T>(T typedMessage, string action, string ns, string filename) { TypedMessageConverter converter = TypedMessageConverter.Create(typeof(T), action, ns); using (Message message = converter.ToMessage(typedMessage)) { using (XmlWriter writer = new XmlTextWriter(filename, Encoding.UTF8)) { message.WriteMessage(writer); } } }
public static void Main() { TypedMessageConverter c = TypedMessageConverter.Create( typeof(Test), "http://tempuri.org/MyTest"); Message msg = c.ToMessage(new Test()); MessageBuffer mb = msg.CreateBufferedCopy(10); using (XmlWriter w = XmlWriter.Create(Console.Out)) { mb.CreateMessage().WriteMessage(w); } Test t = (Test)c.FromMessage(mb.CreateMessage()); }
public static void Test() { TypedMessageConverter tmc = TypedMessageConverter.Create(typeof(MyMC), "Action"); Message msg = tmc.ToMessage(new MyMC { MyMessage = "some string" }, MessageVersion.Soap11); Console.WriteLine(msg); // message with the <MyMessage> element Console.WriteLine(); msg = Message.CreateMessage(MessageVersion.Soap11, "Action", new MyBodyWriter()); Console.WriteLine(msg); // message without the <MyMessage> element }
public void StandardRoundtrip() { TypedMessageConverter c = TypedMessageConverter.Create( typeof(Test1), "http://tempuri.org/MyTest"); Test1 t1 = new Test1(); t1.echo.msg = "test"; t1.body2 = "testtest"; Message msg = c.ToMessage(t1); Test1 t2 = (Test1)c.FromMessage(msg); Assert.AreEqual("test", t2.echo.msg, "#01"); Assert.AreEqual("testtest", t2.body2, "#02"); }
/// <summary> /// Use XmlSerializerUtils to serialize the request into XML. /// </summary> /// <param name="message">SoapMessage to serialize.</param> public static void SerializeRequest(SoapMessage message) { if (message.RequestBodyPayload == null) { message.RequestBodyPayloadText = string.Empty; return; } if (message.RequestBodyPayload is string) { message.RequestBodyPayloadText = message.RequestBodyPayload.ToString(); return; } try { TypedMessageConverter converter = null; try { //Serialize Tourico request type using TypedMessageConverter to get exactly the same XML format to POST converter = TypedMessageConverter.Create ( message.RequestBodyPayload.GetType(), null, //Dont specify Action name here - Action would part of POST header new XmlSerializerFormatAttribute() ); } catch (ArgumentException) { Logger.Instance.Warn("TouricoMessageHelper", "SerializeRequest", "Unable to Serialize using TypedMessageConverter"); } //Convert to XML representation string payloadString = converter.ToMessage(message.RequestBodyPayload, MessageVersion.Soap11).ToString(); //Parse payload var doc = XDocument.Parse(payloadString); var result = doc.ToString(); message.RequestBodyPayloadText = result; } catch (Exception ex) { Logger.Instance.Error("TouricoMessageHelper", "SerializeRequest", ex, "Unable to serialize request body."); throw; } }
protected override Message ToMessageCore(MessageDelivery delivery) { if (!_converterHash.ContainsKey(delivery.Action)) { throw new InvalidOperationException("Unsupported action"); } TypedMessageConverter converter = getCachedConverter(delivery.Action); if (converter != null) { return(converter.ToMessage(delivery.Message)); } else { return(null); } }
public void StandardRoundtrip2() { TypedMessageConverter c = TypedMessageConverter.Create( typeof(Test2), "http://tempuri.org/MyTest"); var t1 = new Test2(); t1.Body = new Echo() { msg = "test" }; var uid = Guid.NewGuid(); t1.Id = uid; Message msg = c.ToMessage(t1); var t2 = (Test2)c.FromMessage(msg); Assert.AreEqual("test", t2.Body.msg, "#01"); Assert.AreEqual(uid, t2.Id, "#02"); }
/// <summary> /// reply the end of message to the client. /// </summary> /// <param name="callback">the response service callback.</param> /// <param name="clientData">the client data.</param> /// <param name="clientPurged">indicating the client purged flag</param> private void ReplyEndOfMessage(IResponseServiceCallback callback, string clientData, EndOfResponsesReason reason) { if (this.callbackChannelDisposed) { return; } BrokerTracing.TraceInfo("[GetResponsesHandler] Client {0}: Send end of response, clientPurged = {1}", this.clientId, reason); this.ResetTimeout(); TypedMessageConverter converter = TypedMessageConverter.Create(typeof(EndOfResponses), Constant.EndOfMessageAction); EndOfResponses endOfResponses = new EndOfResponses(); endOfResponses.Count = this.ResponsesCount; endOfResponses.Reason = reason; Message eom = converter.ToMessage(endOfResponses, this.Version); eom.Headers.Add(MessageHeader.CreateHeader(Constant.ResponseCallbackIdHeaderName, Constant.ResponseCallbackIdHeaderNS, clientData)); this.eorReplied = true; try { if (callback is AzureQueueProxy) { callback.SendResponse(eom, clientData); } else { callback.SendResponse(eom); } } catch (ObjectDisposedException) { BrokerTracing.TraceEvent(System.Diagnostics.TraceEventType.Error, 0, "[BrokerClient] Client {0}: Send end of response error: communication object is disposed.", this.clientId); this.callbackChannelDisposed = true; this.Queue.ResetResponsesCallback(); } catch (Exception ce) { BrokerTracing.TraceEvent(System.Diagnostics.TraceEventType.Error, 0, "[BrokerClient] Client {0}: Send end of response error: {1}", this.clientId, ce); // Swallow exception } }