Editar

Compartilhar via


Get Metadata Using WS-Metadata Exchange in SAP

As a Windows Communication Foundation (WCF) custom binding, the Microsoft BizTalk Adapter for mySAP Business Suite exposes a WS-Metadata Exchange (MEX) endpoint that you can use to retrieve metadata for specific operations from the Microsoft BizTalk Adapter for mySAP Business Suite.

WCF provides a rich infrastructure for exporting, publishing, retrieving and importing metadata about a service. WCF services, like the adapter, use metadata to describe how to interact with the service endpoints so that tools, like svcutil.exe, can automatically generate client code for consuming the service. WCF represents the metadata for a service as an instance of the MetadataSet type, which is strongly tied to the metadata serialization format defined in WS-Metadata Exchange (MEX). You can create a MetadataSet for targeted operations on the adapter by using a MetadataExchangeClient.

WCF support for metadata exchange is an expansive topic and beyond the scope of this documentation. For more information about support for metadata in WCF, see "Metadata" in the WCF documentation at https://go.microsoft.com/fwlink/?LinkId=105634. For a particularly good description of the architecture, classes, and namespaces that WCF exposes for metadata, see "Metadata Architecture Overview" at https://go.microsoft.com/fwlink/?LinkId=105635. You should familiarize yourself with the content related to retrieving metadata from a WCF service in these WCF topics before proceeding.

The following topics contain information about how to use a MetadataExchangeClient to retrieve metadata from the SAP adapter.

Using a MetadataExchangeClient to Retrieve Metadata

To use a MetadataExchangeClient you must specify a connection URI and a binding (SAPBinding). The connection URI identifies the operations for which you want to retrieve metadata.

The following sections contain information about how to specify the connection URI, important binding properties, and how to use a MetadataExchangeClient to retrieve metadata from the adapter.

The Connection URI

To use the MetadataExchangeClient you must supply a SAP connection URI that specifies a MEX endpoint and the operation or operations for which you want to retrieve metadata. You specify a MEX endpoint and target operations in the connection URI in the following manner:

  • You must include the "wsdl" parameter in the query string. If it is the first parameter in the query string, it is specified just after the question mark (?). If it is not the first parameter, it should be preceded with an ampersand (&).

  • You must follow the "wsdl" parameter by one or more "op" parameters. Each "op" parameter is preceded by an ampersand (&) and specifies the message action (node ID) of a target operation.

    For example, the following connection URI targets the Send operation for the SALESORDER_CREATEFROMDAT201 IDOC and the SALESORDER_CREATEFROMDAT202 IDOC. The "wsdl" and "op" parameters are highlighted.

"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"

Note

It is not necessary to include listener parameters in the connection URI for inbound operations. The adapter connects as a client to retrieve metadata from the SAP system.

You can also use the constants defined at Microsoft.Adapters.SAP.SAPAdapterConstants.ActionConstants to help you specify operations when you create a connection URI. This is demonstrated in the code example at the end of this topic.

How you pass this connection URI to the MetadataExchangeClient depends on which of the overloaded methods you use to create the client and retrieve metadata from the adapter.

For more information about the SAP connection URI, see Create the SAP System Connection URI.

Binding Properties

When you create the MetadataExchangeClient, you must specify an SAPBinding.

There are several binding properties that affect how the adapter generates metadata. These properties are:

  • GenerateFlatfileCompatibleIdocSchema

  • ReceiveIDocFormat

  • EnableSafeTyping

  • FlatFileSegmentIndicator

    You should ensure that these binding properties are set to the values required for your application before you invoke the GetMetadata method on the MetadataExchangeClient. For more information about the SAP adapter binding properties, see Read about BizTalk Adapter for mySAP Business Suite Binding Properties.

Example

The following example uses a MetadataExchangeClient to create a service description (WSDL document) for the BAPI_TRANSACTION_COMMIT and BAPI_TRANSACTION_ROLLBACK operations.

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");

            }

        }
    }
}

See Also

Retrieving Metadata Programmatically from SAP Retrieving Metadata in SAP using IMetadataRetrievalContract