在 SAP 中使用 WS-Metadata Exchange 取得元數據
作為 Windows Communication Foundation (WCF) 自定義系結,Microsoft BizTalk Adapter for mySAP Business Suite 會公開 WS-Metadata Exchange (MEX) 端點,可用來從 Microsoft BizTalk Adapter for mySAP Business Suite 擷取特定作業的元數據。
WCF 提供豐富的基礎結構,可用來匯出、發佈、擷取及匯入服務的相關元數據。 WCF 服務,例如配接器,使用元數據來描述如何與服務端點互動,讓 svcutil.exe 之類的工具可以自動產生用戶端程式代碼來取用服務。 WCF 代表服務的元數據做為 MetadataSet 類型的實例,此類型與 WS-Metadata exchange (MEX) 中所定義的元數據串行化格式緊密系結。 您可以使用 MetadataExchangeClient,為適配卡上的目標作業建立 MetadataSet。
元數據交換的 WCF 支援是廣泛的主題,超出本文件的範圍。 如需 WCF 中元數據支援的詳細資訊,請參閱 WCF 檔中 https://go.microsoft.com/fwlink/?LinkId=105634的。 如需 WCF 針對元數據所公開之架構、類別和命名空間的特別好描述,請參閱 上的 https://go.microsoft.com/fwlink/?LinkId=105635。 您應該先熟悉從這些 WCF 主題中從 WCF 服務擷取元數據的相關內容,再繼續進行。
下列主題包含如何使用 MetadataExchangeClient 從 SAP 配接器擷取元數據的相關信息。
使用 MetadataExchangeClient 擷取元數據
若要使用 MetadataExchangeClient ,您必須指定連線 URI 和系結 (SAPBinding) 。 線上 URI 會識別您要擷取元數據的作業。
下列各節包含如何指定連線 URI、重要系結屬性,以及如何使用 MetadataExchangeClient 從配接器擷取元數據的相關信息。
線上 URI
若要使用 MetadataExchangeClient ,您必須提供 SAP 連線 URI,指定 MEX 端點,以及您想要擷取元數據的作業或作業。 您可以使用下列方式,在連線 URI 中指定 MEX 端點和目標作業:
您必須在查詢字串中包含 「wsdl」 參數。 如果它是查詢字串中的第一個參數,則會在問號 (?) 之後指定。 如果不是第一個參數,它應該前面加上 ampersand (&) 。
您必須遵循 「wsdl」 參數一或多個 「op」 參數。 每個 「op」 參數前面都會加上 ampersand (&) ,並指定目標作業 (節點識別碼) 的訊息動作。
例如,下列連線 URI 是以 SALESORDER_CREATEFROMDAT201 IDOC 和 SALESORDER_CREATEFROMDAT202 IDOC 的 Send 作業為目標。 “wsdl” 和 “op” 參數會反白顯示。
"sap://User=YourUserName;Passwd=YourPassword;Client=800;Lang=EN;@a/YourSAPHost/00?wsdl&op=http://Microsoft.LobServices.Sap/2007/03/Idoc/3/SALESORDER_CREATEFROMDAT201//620/Send&op=http://Microsoft.LobServices.Sap/2007/03/Idoc/3/SALESORDER_CREATEFROMDAT202//620/Send"
注意
不需要在輸入作業的連線 URI 中包含接聽程式參數。 配接器會以用戶端的形式連線,以從 SAP 系統擷取元數據。
您也可以使用 定義的 Microsoft.Adapters.SAP.SAPAdapterConstants.ActionConstants
常數,協助您在建立連線 URI 時指定作業。 本主題結尾的程式代碼範例會示範這一點。
如何將此連線 URI 傳遞至 MetadataExchangeClient 取決於您用來建立用戶端並從配接器擷取元數據的多載方法。
如需 SAP 連線 URI 的詳細資訊,請參閱 建立 SAP 系統連線 URI。
系結屬性
當您建立 MetadataExchangeClient 時,您必須指定 SAPBinding。
有數個系結屬性會影響配接器產生元數據的方式。 這些屬性是:
GenerateFlatfileCompatibleIdocSchema
ReceiveIDocFormat
EnableSafeTyping
FlatFileSegmentIndicator
在元數據ExchangeClient 上叫用 GetMetadata 方法之前,您應該確定這些系結屬性已設定為應用程式所需的值。 如需 SAP 配接器系結屬性的詳細資訊,請參閱 閱讀 BizTalk Adapter for mySAP Business Suite 系結屬性。
範例
下列範例會使用 MetadataExchangeClient 建立服務描述, (WSDL 檔) BAPI_TRANSACTION_COMMIT 和BAPI_TRANSACTION_ROLLBACK作業。
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.ObjectModel;
// Needed for WCF and SAP adapter
using System.ServiceModel;
using Microsoft.ServiceModel.Channels;
using Microsoft.Adapters.SAP;
// Needed for MetadataExchangeClient class
using System.ServiceModel.Description;
// Needed for ServiceDescription class
using System.Web.Services;
namespace SapMetadataExchangeClient
{
class Program
{
static void Main(string[] args)
{
//Create a binding
SAPBinding binding = new SAPBinding();
//Create a metadata exchange client that will retrieve metadata according to the WS-MEX standard.
MetadataExchangeClient client = new MetadataExchangeClient(binding);
client.SoapCredentials.UserName.UserName = "YourUserName";
client.SoapCredentials.UserName.Password = "YourPassword";
//Set up an endpoint address and specify the operation for which we want metadata.
string connectionUri = "sap://Client=800;lang=EN@A/YourSAPHost/00?wsdl&op="
+ Microsoft.Adapters.SAP.SAPAdapterConstants.ActionConstants.RfcActionPrefix
+ "BAPI_TRANSACTION_COMMIT"
+ "&op="
+ Microsoft.Adapters.SAP.SAPAdapterConstants.ActionConstants.RfcActionPrefix
+ "BAPI_TRANSACTION_ROLLBACK";
EndpointAddress address = new EndpointAddress(connectionUri);
//Get the metadata.
MetadataSet ms = client.GetMetadata(address);
// Check for the metadata set size.
Collection<MetadataSection> documentCollection = ms.MetadataSections;
if (documentCollection != null && documentCollection.Count > 0)
{
//Get the WSDL from the metadata set
System.Web.Services.Description.ServiceDescription wsdl = (System.Web.Services.Description.ServiceDescription)documentCollection[0].Metadata;
//Save the WSDL to a file.
wsdl.Write("BapiTx.wsdl");
}
}
}
}