/// <summary> /// Sends a message to the specified destination. /// </summary> /// <param name="m">The message to send.</param> /// <param name="destination">The address of the destination to send the message to.</param> public void Send(TransportMessage m, Address destination) { string initiator; if (!m.Headers.TryGetValue(ServiceBrokerTransportHeaderKeys.InitiatorService, out initiator)) { initiator = InitiatorService; } new ServiceBrokerTransactionManager(ConnectionString).RunInTransaction( transaction => { // Always begin and end a conversation to simulate a monologe var conversationHandle = ServiceBrokerWrapper. BeginConversation( transaction, initiator, destination.ToString(), Constants.NServiceBusTransportMessageContract); // Use the conversation handle as the message Id m.Id = conversationHandle.ToString(); // Set the time from the source machine when the message was sent m.SetHeader(ServiceBrokerTransportHeaderKeys.UtcTimeSent, DateTime.UtcNow.ToString(CultureInfo.InvariantCulture)); // Serialize the transport message var xml = SerializeToXml(m); ServiceBrokerWrapper.Send( transaction, conversationHandle, Constants.NServiceBusTransportMessage, Encoding.Unicode.GetBytes(xml)); ServiceBrokerWrapper.ForceEndConversation(transaction, conversationHandle); }); }
/// <summary> /// Sends a message to the specified destination. /// </summary> /// <param name="m">The message to send.</param> /// <param name="destination">The address of the destination to send the message to.</param> public void Send(TransportMessage m, Address destination) { string initiator; if (!m.Headers.TryGetValue(ServiceBrokerTransportHeaderKeys.InitiatorService, out initiator)) initiator = InitiatorService; new ServiceBrokerTransactionManager(ConnectionString).RunInTransaction( transaction => { // Always begin and end a conversation to simulate a monologe var conversationHandle = ServiceBrokerWrapper. BeginConversation( transaction, initiator, destination.ToString(), Constants.NServiceBusTransportMessageContract); // Use the conversation handle as the message Id m.Id = conversationHandle.ToString(); // Set the time from the source machine when the message was sent m.SetHeader(ServiceBrokerTransportHeaderKeys.UtcTimeSent, DateTime.UtcNow.ToString(CultureInfo.InvariantCulture)); // Serialize the transport message var xml = SerializeToXml(m); ServiceBrokerWrapper.Send( transaction, conversationHandle, Constants.NServiceBusTransportMessage, Encoding.Unicode.GetBytes(xml)); ServiceBrokerWrapper.ForceEndConversation(transaction, conversationHandle); }); }
/// <summary> /// Sends a message to the specified destination. /// </summary> /// <param name="m">The message to send.</param> /// <param name="destination">The address of the destination to send the message to.</param> public void Send(TransportMessage m, Address destination) { new SqlServiceBrokerTransactionManager("TODO").RunInTransaction( transaction => { // Always begin and end a conversation to simulate a monologe var conversationHandle = ServiceBrokerWrapper. BeginConversation( transaction, m.ReplyToAddress.ToString(), destination.ToString(), NServiceBusTransportMessageContract); // Use the conversation handle as the message Id m.Id = conversationHandle.ToString(); // Set the time from the source machine when the message was sent m.SetHeader("TimeSent", DateTime.UtcNow.ToString(CultureInfo.InvariantCulture)); using (var stream = new MemoryStream()) { // Serialize the transport message SerializeToXml(m, stream); ServiceBrokerWrapper.Send( transaction, conversationHandle, NServiceBusTransportMessage, stream.GetBuffer()); } ServiceBrokerWrapper.EndConversation (transaction, conversationHandle); }); }