FILE 송신 포트를 통해 AS2 메시지 보내기
AS2 메시지는 일반적으로 HTTP 어댑터를 통해 전송됩니다. 그러나 사용자 지정 구성 요소를 만드는 경우 FILE 어댑터를 통해 AS2 메시지를 보낼 수 있습니다. 이 항목에서는 이러한 솔루션이 작동하는 방식에 대해 설명하고 솔루션의 샘플 코드를 제공합니다.
AS2 메시지가 HTTP를 통해 전송되는 경우 송신 파이프라인의 AS2 인코더는 메시지를 보내는 데 필요한 HTTP(및 AS2) 헤더로 HTTP.UserHttpHeaders
컨텍스트 속성을 채웁니다. 이 AS2 인코더는 기존 HTTP.UserHttpHeaders
컨텍스트 속성, 별도의 컨텍스트 속성 또는 규약 속성(표시된 우선 순위 순서를 따름)에서 이러한 헤더를 가져옵니다. 송신 포트의 HTTP 어댑터는 메시지에 헤더를 기록하고 HTTP를 통해 메시지를 보냅니다.
송신 포트에서 HTTP 어댑터 대신 FILE 어댑터를 사용하는 경우 HTTP.UserHttpHeaders
컨텍스트 속성의 헤더 값이 메시지에 기록되지 않습니다. HTTP.UserHttpHeaders
의 헤더를 메시지 앞에 추가하려면 사용자 지정 파이프라인 구성 요소를 만들어야 합니다. 이렇게 하면 이 메시지가 FILE 어댑터에 의해 폴더에 삽입될 수 있으며 필요한 HTTP 헤더가 포함된 AS2 메시지가 됩니다.
모든 AS2 헤더가 HTTP.UserHttpHeaders
컨텍스트 속성에 포함되도록 하려면 사용자 지정 구성 요소를 만들어야 할 수도 있습니다. AS2 인코더 앞에 사용자 지정 오케스트레이션 또는 사용자 지정 파이프라인 구성 요소를 만들어 AS2 인코더가 HTTP.UserHttpHeaders
를 만드는 데 사용하는 컨텍스트 속성을 설정할 수 있습니다.
AS2 메시지에 헤더 기록
HTTP 어댑터 대신 FILE 어댑터를 사용하여 AS2 메시지를 생성하려면 사용자 지정 AS2 송신 파이프라인에서 AS2 인코더 뒤에 사용자 지정 파이프라인 구성 요소를 추가한 다음 HTTP.UserHttpHeaders
컨텍스트 속성의 헤더를 메시지에 기록하는 코드를 사용자 지정 파이프라인 구성 요소에 포함합니다. 다음 샘플 코드를 예로 들 수 있습니다.
public IBaseMessage Execute(IPipelineContext pContext, IBaseMessage pInMsg)
{
IPipelineContext pipelineContext = pContext;
IBaseMessage baseMessage = pInMsg;
//Prepend Headers
MemoryStream ms = new MemoryStream();
string strName = "UserHttpHeaders";
string strValue = (string)baseMessage.Context.Read(strName,
"http://schemas.microsoft.com/BizTalk/2003/
http-properties");
//Leave an empty line between the headers and the body
strValue += "\r\n";
ms.Write(Encoding.ASCII.GetBytes(strValue), 0,
Encoding.ASCII.GetByteCount(strValue));
//Append Body
Stream sr = baseMessage.BodyPart.Data;
//Read the body of the message and append it to the memory
stream containing the headers
int size = 1024;
byte[] buffer = new byte[size];
while (0 != (size = sr.Read(buffer, 0, buffer.Length)))
{
ms.Write(buffer, 0, size);
}
//Set the body of the message to the new memory stream
baseMessage.BodyPart.Data = ms;
//Rewind the stream
ms.Seek(0, SeekOrigin.Begin);
return baseMessage;
}
AS2 헤더 컨텍스트 속성 승격
사용자 지정 오케스트레이션 또는 사용자 지정 파이프라인 구성 요소를 사용하여 메시지의 컨텍스트로 AS2 헤더 속성을 승격할 수 있습니다.
사용자 지정 파이프라인 구성 요소를 사용하여 AS2 헤더 속성을 승격하려면 사용자 지정 AS2 송신 파이프라인에서 AS2 인코더 앞에 사용자 지정 파이프라인 구성 요소를 추가합니다. HTTP.UserHttpHeaders
의 헤더를 메시지에 기록하는 데 위에 나와 있는 샘플 코드를 사용할 수 있습니다. 단, Read 메서드를 Promote 메서드와 바꾸어 승격할 컨텍스트 속성의 이름, 값 및 네임스페이스를 제공해야 합니다.
사용자 지정 오케스트레이션을 사용하여 AS2 헤더 속성을 승격하려면 FILE 수신 포트, Construct Message 셰이프 및 FILE 송신 포트를 사용하여 오케스트레이션을 만듭니다. Construct Message 셰이프에 AS2 헤더가 포함된 승격 속성을 설정하는 코드를 추가합니다. 사용자 지정 오케스트레이션에서 Microsoft.BizTalk.HttpTransport.dll
에 대한 참조를 추가해야 합니다.
HTTP 헤더의 네임스페이스는 비 AS2 HTTP 헤더의 경우 http://schemas.microsoft.com/BizTalk/2003/http-properties
이고 AS2 헤더의 경우 http://schemas.microsoft.com/BizTalk/2003/as2-properties
입니다.
다음 샘플 코드에서는 오케스트레이션의 Construct Message 셰이프에서 AS2 헤더 속성을 승격하는 방법을 보여 줍니다. 이 코드에서는 MDN의 AS2 헤더를 승격합니다.
Message_2=new System.Xml.XmlDocument();
Message_2=Message_1;
Message_2(EdiIntAS.IsAS2PayloadMessage)=false;
Message_2(EdiIntAS.IsAS2AsynchronousMdn)=true;
Message_2(EdiIntAS.IsAS2MdnResponseMessage)=true;
Message_2(EdiIntAS.SendMDN)=true;
Message_2(EdiIntAS.IsAS2MessageSigned)=false;
Message_2(EdiIntAS.AS2To)="Party1";
Message_2(EdiIntAS.AS2From)="Home";
Message_2(EdiIntAS.MessageId)="123456";
Message_2(EdiIntAS.OriginalMessageId)="2123456";
Message_2(HTTP.UserHttpHeaders)="Message1-Id: xyz\r\nMyHeader: MyValue";