WCF 서비스 모델을 사용하여 SAP에IDOC 보내기
내부적으로 mySAP Business Suite용 Microsoft BizTalk 어댑터는 다음 두 RFC 중 하나를 호출하여 SAP 시스템에 IOC를 보냅니다.
버전 3IDOC에 대한 IDOC_INBOUND_ASYNCHRONOUS.
버전 2의 INBOUND_IDOC_PROCESS.
적절한 RFC(또는 tRFC)를 호출하여 어댑터에 IDOC를 보낼 수 있습니다. 그러나 다음 두 가지 작업을 사용하여 어댑터로 IDOC를 보낼 수도 있습니다.
SendIdoc 는 IDOC 루트 노드 바로 아래에 표시됩니다. SendIdoc 작업은 IDOC를 문자열(약한 형식) 데이터로 SAP 어댑터로 보냅니다.
보내기 는 각 IDOC에 대해 개별적으로 표시됩니다. 보내기 작업은 IDOC를 강력한 형식의 데이터로 SAP 어댑터로 보냅니다.
이러한 작업은 IDOC 데이터가 SAP 시스템으로 전송되는 방식이 아니라 어댑터로 전송되는 방법을 결정합니다. 어댑터는 항상 적절한 tRFC를 사용하여 IDOC를 SAP 시스템으로 보냅니다.
SAP 어댑터는 IDOC를 tRFC로 보내기 때문에 Send 및 SendIdoc 작업 모두 IDOC를 확인(커밋)하는 데 사용하는 GUID 매개 변수를 노출합니다. SAP 어댑터는 이 GUID를 tRFC와 연결된 SAP TID(트랜잭션 ID)와 내부적으로 매핑합니다. 다음 두 가지 방법 중 하나로 IDOC를 확인할 수 있습니다.
AutoConfirmSentIdocs 바인딩 속성을 사용합니다. 이 바인딩 속성이 true로 설정된 경우 어댑터는 IDOC를 보내는 데 사용되는 tRFC를 자동으로 확인합니다.
RfcConfirmTransID를 호출합니다. IDOC와 연결된 GUID를 사용하여 이 작업을 호출합니다.
다음 섹션에서는 SendIdoc 및 보내기 작업을 사용하여 SAP 시스템에IDOC를 보내는 방법을 보여 줍니다. IDOC를 tRFC로 보내는 데 도움이 되는 자세한 내용은 WCF 서비스 모델을 사용하여 SAP에서 tRFC 호출을 참조하세요.
WCF 클라이언트 클래스
SendIdoc 작업
SAP 어댑터는 IDOC를 문자열 형식으로 보내기 위한 단일 작업(및 서비스 계약)을 표시합니다. 서비스 계약의 이름은 "Idoc"이고 WCF 클라이언트 클래스는 IdocClient입니다.
이 클라이언트를 사용하여 모든 IDOC를 SAP로 보낼 수 있습니다. 여기에는 두 개의 매개 변수를 사용하는 단일 메서드 SendIdoc가 포함되어 있습니다.
idocData 는 IDOC 데이터를 포함하는 문자열입니다.
guid 는 SAP TID에 매핑되는 GUID입니다.
다음 코드는 SendIdoc 작업에 대해 생성된 WCF 클라이언트를 보여줍니다.
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
public partial class IdocClient : System.ServiceModel.ClientBase<Idoc>, Idoc {
public void SendIdoc(string idocData, ref System.Nullable\<System.Guid\> guid) {…}
}
보내기 작업
보내기 작업은 강력한 형식의 데이터를 사용하므로 SAP 어댑터는 각 IDOC에 대한 고유한 서비스 계약을 표시합니다. 이 계약에 대해 생성된 인터페이스(및 WCF 클라이언트 클래스)의 이름은 IDOC 유형, 버전, 릴리스 번호 및 CIM 유형(관련된 경우)을 기반으로 합니다. 예를 들어 ORDERS03.v3.620 IDOC의 경우 인터페이스 이름은 "IdocORDERS03V3R620"이고 WCF 클라이언트 클래스는 IdocORDERS03V3R620Client입니다.
각 IDOC 유형에 대해 고유한 클라이언트를 생성해야 합니다. 이 클라이언트에는 두 개의 매개 변수를 사용하는 단일 메서드 Send가 포함되어 있습니다.
idocData 는 강력한 형식의 IDOC 데이터를 나타내는 클래스입니다.
guid 는 SAP TID에 매핑되는 GUID의 문자열 표현입니다.
다음 코드는 ORDERS03.v3.620 IDOC에 대해 표시되는 보내기 작업에 대해 생성된 WCF 클라이언트를 보여 줍니다.
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
public partial class IdocORDERS03V3R620Client : System.ServiceModel.ClientBase<IdocORDERS03V3R620>, IdocORDERS03V3R620 {
...
public void Send(ORDERS03 idocData, ref string guid) { ... }
}
애플리케이션을 만들어 IDOC를 보내는 방법
SAP 시스템에 IDOC를 보내려면 다음 단계를 수행합니다.
SAP 시스템에 IDOC를 보내려면
WCF 클라이언트 클래스를 생성합니다. 어댑터 서비스 참조 Visual Studio 플러그 인 추가 또는 ServiceModel 메타데이터 유틸리티 도구(svcutil.exe)를 사용하여 작업하려는 IDOC를 대상으로 하는 WCF 클라이언트 클래스를 생성합니다. WCF 클라이언트를 생성하는 방법에 대한 자세한 내용은 SAP 솔루션 아티팩트용 WCF 클라이언트 또는 WCF 서비스 계약 생성을 참조하세요. IDOC를 명시적으로 확인하려면 RfcConfirmTransID 작업에 대한 WCF 클라이언트를 생성해야 합니다. 작업은 다음 노드에서 찾을 수 있습니다.
SendIdoc 작업. IDOC 노드 바로 아래에 있습니다.
보내기 작업. 대상 IDOC의 형식, 버전 및 릴리스 번호에 해당하는 노드 아래에 있습니다.
RfcConfirmTransID 작업. TRFC 노드 바로 아래에 있습니다.
1단계에서 생성된 WCF 클라이언트 클래스의 instance 만들고 클라이언트 바인딩을 지정합니다. 클라이언트 바인딩을 지정하려면 WCF 클라이언트에서 사용할 바인딩 및 엔드포인트 주소를 지정해야 합니다. 코드에서 명령적으로 또는 구성에서 선언적으로 이 작업을 수행할 수 있습니다. 클라이언트 바인딩을 지정하는 방법에 대한 자세한 내용은 SAP 시스템에 대한 클라이언트 바인딩 구성을 참조하세요. 다음 코드는 구성에서 IdocClient(보내기 작업의 경우)를 초기화하고 SAP 시스템에 대한 자격 증명을 설정합니다.
SAPBinding binding = new SAPBinding(); // Set endpoint address EndpointAddress endpointAddress = new EndpointAddress("sap://CLIENT=800;LANG=EN;@a/YourSAPHost/00?RfcSdkTrace=False&AbapDebug=False&UseSapGui=Without"); // Create client and set credentials idocClient = new IdocClient(binding, endpointAddress); idocClient.ClientCredentials.UserName.UserName = "YourUserName"; idocClient.ClientCredentials.UserName.Password = "YourPassword";;
어댑터가 IDOC를 보낸 후 SAP 시스템에서 tRFC를 확인하려면 AutoConfirmSentIdocs 바인딩 속성을 true로 설정합니다. WCF 클라이언트를 열기 전에 이 작업을 수행해야 합니다.
// Set AutoConfirmSentIdocs property to true binding.AutoConfirmSentIdocs = true;
WCF 클라이언트를 엽니다.
idocClient.Open();
2단계에서 만든 WCF 클라이언트에서 적절한 메서드를 호출하여 IDOC를 SAP 시스템으로 보냅니다. GUID를 포함하거나 guid 매개 변수에 대해 null로 설정된 변수를 전달할 수 있습니다. GUID를 지정하지 않으면 SAP 어댑터가 작업에 대해 GUID를 생성합니다(guid 는 ref 매개 변수임). 다음 코드는 파일에서 IDOC(문자열 형식)를 읽고 SendIdoc 작업을 사용하여 SAP 시스템으로 보냅니다.
// Read IDOC into string variable using (StreamReader reader = new StreamReader("ORDERS03.txt")) { idocData = reader.ReadToEnd(); } //Get a new GUID to pass to SendIdoc. You can also assign a null //value to have the adapter generate a GUID. adapterTxGuid = Guid.NewGuid(); //Invoke SendIdoc on the client to send the IDOC to the SAP system idocClient.SendIdoc(idocData, ref adapterTxGuid);
AutoConfirmSentIdocs 바인딩 속성을 true로 설정하지 않은 경우(3단계에서) SAP 시스템에서 tRFC를 확인해야 합니다. 이렇게 하려면 TrfcClient에서 RfcConfirmTransID 메서드를 호출해야 합니다(생성이 표시되지 않음). 매개 변수에 대해 4단계에서 반환된 GUID를 지정합니다.
trfcClient.RfcConfirmTransID(adapterTxGuid);
WCF 클라이언트(사용된 경우 TrfcClient)를 닫습니다(IDOC 전송을 완료한 후).
idocClient.Close();
예제
다음 예제에서는 SendIdoc 메서드를 사용하여 SAP 시스템에 IDOC를 보냅니다. IDOC는 ORDERS03.txt 파일에서 읽습니다. 이 파일에는 ORDERS03 포함되어 있습니다. V3.620 IDOC 및 는 샘플에 포함됩니다. 그러나 SendIdoc 작업을 사용하여 모든 IDOC를 보낼 수 있습니다.
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
// Add WCF, WCF LOB Adapter SDK, and SAP adapter namepaces
using System.ServiceModel;
using Microsoft.Adapters.SAP;
using Microsoft.ServiceModel.Channels;
// Include this namespace for WCF LOB Adapter SDK and SAP exceptions
using Microsoft.ServiceModel.Channels.Common;
// This example sends a flat IDOC to the SAP system by using the SendIdoc operation.
namespace SapIdocStringClientSM
{
class Program
{
static void Main(string[] args)
{
// variable for the IDOC client
IdocClient idocClient = null;
Console.WriteLine("IDOC string client sample started");
try
{
// Variable for the GUID
System.Nullable<System.Guid> adapterTxGuid;
// string to hold the Idoc data
string idocData;
// string to hold the SAP transaction ID (TID)
string sapTxId;
// The client can be configured from app.config, but it is
// explicitly configured here for demonstration.
// set AutoConfirmSentIdocs property to true
SAPBinding binding = new SAPBinding();
binding.AutoConfirmSentIdocs = true;
// Set endpoint address
EndpointAddress endpointAddress = new EndpointAddress("sap://CLIENT=800;LANG=EN;@a/YourSAPServer/00?RfcSdkTrace=False&AbapDebug=False&UseSapGui=Without");
// Create client and set credentials
idocClient = new IdocClient(binding, endpointAddress);
idocClient.ClientCredentials.UserName.UserName = "YourUserName";
idocClient.ClientCredentials.UserName.Password = "YourPassword";
// Open the client and send the Idoc
idocClient.Open();
// Read IDOC into string variable
using (StreamReader reader = new StreamReader("ORDERS03.txt"))
{
idocData = reader.ReadToEnd();
}
//Get a new GUID to pass to SendIdoc. You can also assign a null.
//value to have the adapter generate a GUID.
adapterTxGuid = Guid.NewGuid();
//Invoke SendIdoc on the client to send the IDOC to the SAP system.
idocClient.SendIdoc(idocData, ref adapterTxGuid);
// The AutoConfirmSentIdocs binding property is set to true, so there is no need to
// confirm the IDOC. If this property is not set to true, you must call the
// RfcConfirmTransID method of a TrfcClient with adapterTxGuid to
// confirm the transaction on the SAP system.
// Get SAP tx id from GUID
sapTxId = SAPAdapterUtilities.ConvertGuidToTid((Guid) adapterTxGuid);
Console.WriteLine("IDOC sent");
Console.WriteLine("The SAP Transaction Id is : " + sapTxId);
catch (Exception ex)
{
Console.WriteLine("Exception is: " + ex.Message);
if (ex.InnerException != null)
{
Console.WriteLine("Inner Exception is: " + ex.InnerException.Message);
}
}
finally
{
// Close the IDOC client
if (idocClient != null)
{
if (idocClient.State == CommunicationState.Opened)
idocClient.Close();
else
idocClient.Abort();
}
}
}
}
}