public override void write(Stream s) { // Assemble the Spine synchronous SOAP request and write it to "s". Strip off // any XML PI from the top of the serialised SpineHL7Message. // // 1. Extract the communicationFunctionSnd/Rcv bits of the HL7 message, subsitute them into the template // 2. Substitute in the URL, and the addressing "stuff" (that can come from our IP address // of be loaded from the Registry // 3. Get the serialised XML of the HL7 and strip off any <?xml...?>, // 4. "makeHttpHeader()" with the content length StringBuilder sb = new StringBuilder(template); sb.Replace("__MESSAGE_ID__", messageid); StringBuilder sa = new StringBuilder(transmissionDetails.Service); sa.Append("/"); sa.Append(transmissionDetails.InteractionId); soapAction = sa.ToString(); sb.Replace("__SOAPACTION__", soapAction); sb.Replace("__RESOLVED_URL__", resolvedUrl); sb.Replace("__MY_IP__", myIp); sb.Replace("__TO_ASID__", transmissionDetails.Asid[0]); sb.Replace("__MY_ASID__", myAsid); // Body... string hl7 = hl7Message.serialise(); if (hl7.StartsWith("<?xml ")) { sb.Replace("__HL7_BODY__", hl7.Substring(hl7.IndexOf('>') + 1)); } else { sb.Replace("__HL7_BODY__", hl7); } long l = sb.Length; string hdr = makeHttpHeader(l); StreamWriter t = new StreamWriter(s); t.Write(hdr); t.Write(sb.ToString()); t.Flush(); }
public override void write(Stream s) { StringBuilder sb = new StringBuilder(FIRSTMIMEPREFIX); sb.Append(mimeboundary); sb.Append(header.makeMimeHeader()); sb.Append(header.serialise()); sb.Append(MIMEPREFIX); sb.Append(mimeboundary); sb.Append(hl7message.makeMimeHeader()); sb.Append(hl7message.serialise()); if (attachments != null) { foreach (Attachment a in attachments) { sb.Append(MIMEPREFIX); sb.Append(mimeboundary); sb.Append(a.makeMimeHeader()); sb.Append(a.serialise()); } } sb.Append(MIMEPREFIX); sb.Append(mimeboundary); sb.Append(MIMEPOSTFIX); long l = sb.Length; if (l < MAX_MESSAGE_SIZE) { string hdr = makeHttpHeader(l); StreamWriter t = new StreamWriter(s); t.Write(hdr); t.Write(sb.ToString()); t.Flush(); } else { // NEXT VERSION: Implement this... Bit of an exception case here, may be // better to have a caller-settable flag (or a different method) for "send using large // message protocol". // string mainMessage = sendLargeMessage(sb.ToString()); } }