GetMessages 샘플
이 항목에서는 거부하지 않는 메시지 테이블 또는 LOB(기간 업무) 테이블 중 하나에서 읽을 수 있는 형식으로 메시지를 검색하는 데 사용할 수 있는 샘플 코드를 제공합니다. 부인할 수 없는 메시지 테이블에는 BizTalk Accelerator for RosettaNet(BTARN)Archive 데이터베이스의 MessageStorageIn 및 MessageStorageOut이 포함됩니다. LOB 테이블에는 BTARNDATA 데이터베이스의 MessageFromLOB 및 MessageToLOB가 포함됩니다.
문제 해결 또는 개발에 사용합니다 GetMessages
. 기본적으로 코드는 기본 64 문자열을 반환합니다.
참고
GetMessages.cs 샘플 코드에는 두 개의 코드 섹션이 포함되어 있습니다. 하나는 LOB 테이블 중 하나에서 메시지를 검색하는 섹션이고 다른 하나는 부인하지 않는 테이블 중 하나에서 메시지를 검색하기 위한 것입니다. 각 용도에 맞게 별도의 애플리케이션을 만듭니다.
LOB 테이블에서 메시지를 검색하려면
프로그램에 다음 샘플 코드를 추가합니다.
private static string GetLOBMessage(string sMessageSource, string sMessageID)
매개 변수를
sMessageSource
MessagesFromLOB 또는 MessagesToLOB 테이블로 설정합니다.매개 변수를
sMessageID
데이터베이스의 MessageID 필드 값으로 설정합니다.참고
애플리케이션은 검색된 메시지가 포함된 문자열을 반환합니다.
거부하지 않는 테이블에서 메시지를 검색하려면
프로그램에 다음 샘플 코드를 추가합니다.
private static string GetNRMessage(string sMessageSource, string sMessageID)
매개 변수를
sMessageSource
MessageStorageIn 또는 MessageStorageOut 테이블로 설정합니다.매개 변수를
sMessageID
데이터베이스의 RecordID 필드 값으로 설정합니다.참고
애플리케이션은 검색된 메시지가 포함된 문자열을 반환합니다.
데모
GetMessages 샘플에는 다음 두 가지 코드 섹션이 포함되어 있습니다.
한 섹션에서는 부인할 수 없는 테이블 중 하나에서 이진 메시지를 검색하고 읽을 수 있는 ASCII 양식으로 변환하는 방법을 보여 줍니다.
다른 섹션에서는 LOB 테이블 중 하나에서 메시지를 검색하는 방법을 보여 줍니다. LOB 테이블의 메시지는 이미 ASCII 형식이므로 SQL select 문입니다.
중요
데모를 위해 제공된 샘플 코드는 SQL 삽입 취약성이 발생하기 쉬운 직접 SQL 문을 사용합니다. 프로덕션 환경에서는 이러한 취약성을 방지하기 위해 직접 SQL 문 대신 매개 변수가 있는 SQL 저장 프로시저를 사용하는 것이 좋습니다.
예제
다음 코드 예제의 두 섹션 중 하나를 사용하여 부인할 수 없는 테이블 또는 LOB 테이블 중 하나에서 메시지를 검색합니다.
using System;
using System.Text;
using System.Data.SqlClient;
using Microsoft.Solutions.BTARN.Shared;
namespace Microsoft.Solutions.BTARN.Admin
{
/// <summary>
/// Summary description for GetMessages.
/// </summary>
class GetMessages
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
Console.WriteLine(GetLOBMessage("MessagesFromLOB", "bce5b580daf543a990a4f37331f31e42"));
Console.WriteLine(GetLOBMessage("MessagesToLOB", "bce5b580daf543a990a4f37331f31e42"));
Console.WriteLine(GetNRMessage("MessageStorageIn", "dc06e9cfecd746a889dd6ea7beb3ba21"));
Console.WriteLine(GetNRMessage("MessageStorageOut", "dc06e9cfecd746a889dd6ea7beb3ba21"));
}
/// <summary>
/// Retrieve a message from the LOB tables in the BTARNDATA database
/// </summary>
/// <param name="sMessageSource">Can be either MessagesFromLOB or MessagesToLOB</param>
/// <param name="sMessageID">The value of the MessageID field in the database</param>
/// <returns>Returns a string that contains the retrieved message</returns>
private static string GetLOBMessage(string sMessageSource, string sMessageID)
{
SqlDataReader localReader = null;
SqlConnection sqlConnection = null;
SqlCommand sqlCommand = null;
string sReturnedMessage="";
string sQuery;
sqlConnection = new SqlConnection(RuntimeGlobal.DataDbConnectionString);
sQuery = "SELECT ServiceContent from " + sMessageSource + " WHERE MessageID=N'" + sMessageID +"'";
sqlCommand = new SqlCommand(sQuery, sqlConnection);
sqlConnection.Open();
localReader = sqlCommand.ExecuteReader();
if (localReader.Read())
sReturnedMessage=localReader.GetString(0);
localReader.Close();
sqlConnection.Close();
return sReturnedMessage;
}
/// <summary>
/// Retrieve a message from the non-repudiation tables in the BTARNArchive database
/// </summary>
/// <param name="sMessageSource">Can be either MessageStorageIn or MessageStorageOut</param>
/// <param name="sMessageID">The value of the RecordID field in the database</param>
/// <returns>Returns a string that contains the retrieved message</returns>
private static string GetNRMessage(string sMessageSource, string sMessageID)
{
SqlDataReader localReader = null;
SqlConnection sqlConnection = null;
SqlCommand sqlCommand = null;
string sReturnedMessage="";
string sQuery;
sqlConnection = new SqlConnection(RuntimeGlobal.ArchiveDbConnectionString);
sQuery = "SELECT Content from " + sMessageSource + " WHERE RecordID=N'" + sMessageID +"'";
sqlCommand = new SqlCommand(sQuery, sqlConnection);
sqlConnection.Open();
localReader = sqlCommand.ExecuteReader();
if (localReader.Read())
{
//Determine the size of the field in bytes and create a new byte array
byte[] bData= new byte[localReader.GetBytes(0, 0, null, 0, 0)];
//Read the value of the field into bData
localReader.GetBytes(0, 0, bData, 0, bData.Length);
//Convert the byte array into a string
sReturnedMessage=Encoding.ASCII.GetString(bData);
}
localReader.Close();
sqlConnection.Close();
return sReturnedMessage;
}
}
}