static void Main(string[] args) { IBaseMessage responseMsg = null; // Address of receive locations where to submit message to const string submitURI = "submit://submitrequest"; // Check parameters if (0 == args.Length) { Usage(); return; } //Check if file exists if (!File.Exists(args[0])) { Console.WriteLine("{0} does not exist.", args[0]); return; } // Create BizTalk message submission object BizTalkMessaging btm = new BizTalkMessaging(); // Open the file stream FileStream fileStream = File.Open(args[0], System.IO.FileMode.Open); try { // Submit message and wait for response // The charset information is empty because it will be determined by XML disassembler from BOM of file responseMsg = btm.SubmitSyncMessage(btm.CreateMessageFromStream(submitURI, null, fileStream)); // Get an XML from response and print it out in console window if (null != responseMsg) { if ((responseMsg.BodyPart != null) && (responseMsg.BodyPart.Data != null)) { StreamReader sr = new StreamReader(responseMsg.BodyPart.Data); Console.WriteLine("Response message:"); Console.WriteLine(sr.ReadToEnd()); } } } catch (Exception e) { Console.WriteLine(e.ToString()); } finally { // Close the message submission object btm.Close(); // Close file stream fileStream.Close(); } }
public Task Handle(OrderMessage message, NServiceBus.IMessageHandlerContext context) { try { var serializer = new XmlSerializer(message.GetType()); var messageStream = new MemoryStream(); serializer.Serialize(messageStream, message); messageStream.Seek(0, SeekOrigin.Begin); var btm = new BizTalkMessaging(); var bizTalkMessage = btm.CreateMessageFromStream(SubmitDirectAdapterUri, null, messageStream); btm.SubmitMessage(bizTalkMessage); } catch (Exception ex) { _logger.Error(ex.ToString()); throw; //Throwing the exception will allow NServiceBus to requeue and retry the message } return(Task.CompletedTask); }