Muokkaa

Jaa


Receive Inbound tRFC Calls in SAP using the WCF Service Model

You can use the Microsoft BizTalk Adapter for mySAP Business Suite as a transactional RFC (tRFC) server to receive inbound tRFC calls from SAP. For inbound tRFCs, the SAP adapter supports multiple tRFCs in the same SAP logical unit of work (LUW).

The sections in this topic provide information about how to use the adapter as a tRFC server in the WCF service model.

You can find more information about using the SAP adapter as a tRFC server in the following topics:

The WCF Service Contract for a tRFC

You use the Add Adapter Service Reference Visual Studio Plug-in or the ServiceModel Metadata Utility Tool (svcutil.exe) to generate a WCF service contract for the tRFCs that you want to receive from the SAP system. The contract generated for an inbound tRFC is similar to that generated for an inbound RFC except that:

  • tRFC operations are surfaced under the TRFC node.

  • The WCF service contract (interface) generated for incoming tRFCs is named "Trfc". You must specify this interface when you add the service endpoint to the service host. This is also the interface that your WCF service must implement.

    public interface Trfc {  
    
        // CODEGEN: Generating message contract since the wrapper namespace (http://Microsoft.LobServices.Sap/2007/03/Trfc/) of message Z_RFC_MKD_ADDRequest does not match the default value (http://Microsoft.LobServices.Sap/2007/03/)  
        [System.ServiceModel.OperationContractAttribute(Action="http://Microsoft.LobServices.Sap/2007/03/Trfc/Z_RFC_MKD_ADD", ReplyAction="http://Microsoft.LobServices.Sap/2007/03/Trfc/Z_RFC_MKD_ADD/response")]  
        Z_RFC_MKD_ADDResponse Z_RFC_MKD_ADD(Z_RFC_MKD_ADDRequest request);  
    }  
    
  • The request message contract for TRFC operations has a GUID parameter. This is the GUID that maps to the SAP TID for the tRFC. In tRFC server operations, the adapter manages all calls to commit, rollback, and confirm the TID by the SAP system so there is no reason for you to explicitly use this GUID. However, you can use it to retrieve the SAP TID from the SAP adapter by calling SapAdapterUtilities.ConvertGuidToTid. This can be useful to help you troubleshoot issues on the SAP system.

    [System.Diagnostics.DebuggerStepThroughAttribute()]  
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]  
    [System.ServiceModel.MessageContractAttribute(WrapperName="Z_RFC_MKD_ADD", WrapperNamespace="http://Microsoft.LobServices.Sap/2007/03/Trfc/", IsWrapped=true)]  
    public partial class Z_RFC_MKD_ADDRequest {  
    
        ...  
    
        public Z_RFC_MKD_ADDRequest(string DEST, System.Nullable<int> X, System.Nullable<int> Y, System.Guid TransactionalRfcOperationIdentifier) {  
            this.DEST = DEST;  
            this.X = X;  
            this.Y = Y;  
            this.TransactionalRfcOperationIdentifier = TransactionalRfcOperationIdentifier;  
        }  
    }  
    
    

How do I Enable the Adapter to Act as a tRFC Server?

To enable the adapter to act as a tRFC server, you must set the TidDatabaseConnectionString binding property to the connection string for the TID database. You should do this before you open the service host. This is the database in which the adapter stores the SAP transaction ID (TID) for each tRFC. For more information about this binding property, see Read about BizTalk Adapter for mySAP Business Suite Binding Properties.

Caution

This example or guidance references sensitive information, such as a connection string or a username and password. Never hardcode these values in your code, and make sure that you protect confidential data by using the most secure authentication available. For more information, see the following documentation:

How do I Enlist in the Transaction for Inbound tRFCs?

An SAP Logical Unit of Work (LUW) can contain multiple tRFCs. On the SAP system a LUW is identified by a unique Transaction ID (TID). The adapter creates a committable transaction for each of the TIDs that the SAP system uses when it invokes tRFC calls on the adapter. When the SAP system invokes a tRFC on the adapter; the adapter flows the transaction associated with the SAP TID to your service. You can access this transaction as the ambient transaction from inside your operation method. By enlisting in this ambient transaction, the actions performed in the operation can participate in the SAP LUW.

To enlist in the ambient transaction in an operation method, you must:

  1. Annotate the operation method with the TransactionScopeRequired property of the OperationBehavior attribute. This tells WCF that you want access to the ambient transaction from inside the operation.

  2. Create a transaction scope either by annotating the operation method with the TransactionAutoComplete property of the OperationBehavior attribute or by explicitly using a TransactionScope inside the operation method.

    The following example shows a service that implements two operations. Both operation methods are annotated with the TransactionScopeRequired property to access the ambient transaction.

  • Z_TRFC_EXAMPLE1 explicitly enlists in the transaction by using a TransactionScope object.

  • Z_TRFC_EXAMPLE2 is annotated with the TransactionAutoComplete property to enlist in the transaction

[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, UseSynchronizationContext = false)]  
class Z_Example_ServiceContractClass : Trfc  
{  
  
    // This operation method explicitly creates a TransactionScope to enlist in the ambient transaction  
    // You must explictly call ts.Complete to complete the transaction before you return from the operation  
    // Otherwise the transaction is aborted.  
    // You can throw an exception or return without calling ts.complete to abort the transacation  
    [OperationBehavior(TransactionScopeRequired = true)]  
    public Z_TRFC_EXAMPLE1Response Z_TRFC_EXAMPLE1(Z_TRFC_EXAMPLE1Request request)  
    {  
        using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required))  
        {  
            // Process tRFC  
  
            ...  
  
            Z_TRFC_EXAMPLE1Response response = new Z_TRFC_EXAMPLE1Response();  
            response.TransactionalRfcOperationIdentifier = request.TransactionalRfcOperationIdentifier;  
            return response;  
            //since there is no ts.Complete(), this is equivalent to a rollback.  
        }  
    }  
  
    // This operation method sets the TransactionAutoComplete property of the OperationBehavior attribute  
    // to enlist in the transaction. There is no need to explictly create a TransactionScope in the code.  
    // If the method returns with no unhandled exceptions, the transaction completes; otherwise it aborts  
    // You can throw an exception to abort the transaction.  
    [OperationBehavior(TransactionScopeRequired = true, TransactionAutoComplete = true)]  
    public Z_TRFC_EXAMPLE2Response Z_TRFC_EXAMPLE2(Z_TRFC_EXAMPLE2Request request)  
    {  
        // Process tRFC  
  
        ...  
  
        Z_TRFC_EXAMPLE2Response response = new Z_TRFC_EXAMPLE2Response();  
        response.TransactionalRfcOperationIdentifier = request.TransactionalRfcOperationIdentifier;  
        return response;  
        //if there is no unhandled exception, the transaction completes when the operation returns.  
    }  
}  

See Also

Develop applications using the WCF Service Model