Sending a message is very easy, the framework provides two key classes to help you do this:
  • MLLPMessage
  • MLLPSender

With MLLPMessage you provide a string to be the body of the message. This is normally a string of HL7 data. The MLLPMessage will then deal with any specifics for the MLLP protocol.

MLLPSender will handle the sending of a message. The message can either be sent one way which will expect an empty message back from the sender using the SendOneWay(). method or to get a response/Ack back by using the Send() method.

If a response or acknowledgement is returned then in Specflow I would normally add the message to the ScenarioContext for validation later, but you can do what ever you like with the response as required by your test.

The below is an example of the code to send a message and get a response.

var portName = table.Rows[0]["Port Name"];
            var applicationName = table.Rows[0]["Application Name"];

            var applicationSettings = HL7TestConfiguration.Current.ApplicationsToSendTo.Get(applicationName, portName);

            var message = ScenarioContext.Current[ADTRequestMessageKey] as string;

            var mllpMessage = new MLLPMessage(message);
            var sender = new MLLPSender();
            var responseMllpMessage = sender.Send(applicationSettings.Server, applicationSettings.Port, mllpMessage);
            var rawAck =  responseMllpMessage.RemoveMLLPWrapper();
            ScenarioContext.Current.Add(ADTBizTalkAckMessageKey, rawAck);

Last edited Apr 21, 2014 at 2:01 AM by michaelstephenson, version 1