Пример #1
0
        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();
            }
        }
Пример #2
0
        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);
        }
Пример #3
0
        static void Main(string[] args)
        {
            // Check arguments from command line
            if (0 == args.Length)
            {
                Usage();
                return;
            }

            // Create message submission object
            BizTalkMessaging btm = new BizTalkMessaging();

            // Create the array of messages to submit
            IBaseMessage[] msgs = new IBaseMessage[args.Length];
            try
            {
                // Populate the array of messages
                for (int i = 0; i < args.Length; i++)
                {
                    msgs[i] = btm.CreateMessageFromString(submitURI, args[i]);
                }

                // Submit the messages
                btm.SubmitMessages(msgs);
                Console.WriteLine("Messages have been successfully submitted into the receive location \"{0}\"", submitURI);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
            finally
            {
                // Close the message submission object
                btm.Close();
            }
        }