Share via


Ricevere chiamate tRFC in ingresso in SAP usando il modello di servizio WCF

È possibile usare Microsoft BizTalk Adapter per mySAP Business Suite come server RFC (tRFC) transazionale per ricevere chiamate tRFC in ingresso da SAP. Per i TRFC in ingresso, l'adattatore SAP supporta più TRFC nella stessa unità logica SAP di lavoro (LUW).

Le sezioni di questo argomento forniscono informazioni su come usare l'adattatore come server tRFC nel modello di servizio WCF.

Altre informazioni sull'uso dell'adattatore SAP come server tRFC sono disponibili negli argomenti seguenti:

  • Per una panoramica del supporto per tRFCs nell'adattatore SAP, vedere Operazioni sui TRFC in SAP. Prima di continuare, leggere questo argomento.

  • Per altre informazioni sugli schemi dei messaggi per le operazioni del server tRFC, vedere Operazioni sui TRFC in SAP.

Contratto di servizio WCF per un TRFC

Usare il plug-in Add Adapter Service Reference di Visual Studio o lo strumento serviceModel Metadata Utility (svcutil.exe) per generare un contratto di servizio WCF per i TRFC che si desidera ricevere dal sistema SAP. Il contratto generato per un TRFC in ingresso è simile a quello generato per un RFC in ingresso, ad eccezione del fatto che:

  • Le operazioni tRFC vengono visualizzate nel nodo TRFC.

  • Il contratto di servizio WCF (interfaccia) generato per i TRFC in ingresso è denominato "Trfc". È necessario specificare questa interfaccia quando si aggiunge l'endpoint di servizio all'host del servizio. Si tratta anche dell'interfaccia che il servizio WCF deve implementare.

    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);  
    }  
    
  • Il contratto di messaggio di richiesta per le operazioni TRFC ha un parametro GUID. Si tratta del GUID mappato a SAP TID per tRFC. Nelle operazioni del server tRFC, l'adapter gestisce tutte le chiamate per il commit, il rollback e confermare il TID dal sistema SAP in modo che non vi sia alcun motivo per usare in modo esplicito questo GUID. È tuttavia possibile usarlo per recuperare SAP TID dalla scheda SAP chiamando SapAdapterUtilities.ConvertGuidToTid. Ciò può essere utile per risolvere i problemi nel sistema SAP.

    [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;  
        }  
    }  
    
    

Ricerca per categorie Abilitare l'adapter come server tRFC?

Per consentire all'adattatore di fungere da server tRFC, è necessario impostare la proprietà di associazione TidDatabaseConnectionString sul stringa di connessione per il database TID. È necessario eseguire questa operazione prima di aprire l'host del servizio. Si tratta del database in cui l'adapter archivia l'ID transazione SAP (TID) per ogni tRFC. Per altre informazioni su questa proprietà di associazione, vedere Informazioni sull'adapter BizTalk per le proprietà di associazione mySAP Business Suite.

Ricerca per categorie eseguire l'integrazione nella transazione per i TRFC in ingresso?

Un'unità logica SAP (LUW) può contenere più TRFC. Nel sistema SAP un LUW è identificato da un ID transazione univoco (TID). L'adattatore crea una transazione componibile per ognuno dei TID usati dal sistema SAP quando richiama le chiamate tRFC sull'adapter. Quando il sistema SAP richiama un TRFC sulla scheda; l'adattatore scorre la transazione associata al TID SAP al servizio. È possibile accedere a questa transazione come transazione di ambiente dall'interno del metodo dell'operazione. Eseguendo l'integrazione in questa transazione di ambiente, le azioni eseguite nell'operazione possono partecipare a SAP LUW.

Per integrare la transazione di ambiente in un metodo di operazione, è necessario:

  1. Annotare il metodo operation con la proprietà TransactionScopeRequired dell'attributo OperationBehavior . Indica a WCF di voler accedere alla transazione di ambiente dall'interno dell'operazione.

  2. Creare un ambito di transazione annotando il metodo operation con la proprietà TransactionAutoComplete dell'attributo OperationBehavior o utilizzando in modo esplicito transactionScope all'interno del metodo operation.

    Nell'esempio seguente viene illustrato un servizio che implementa due operazioni. Entrambi i metodi dell'operazione vengono annotati con la proprietà TransactionScopeRequired per accedere alla transazione di ambiente.

  • Z_TRFC_EXAMPLE1 inserisce in modo esplicito nella transazione utilizzando un oggetto TransactionScope .

  • Z_TRFC_EXAMPLE2 viene annotato con la proprietà TransactionAutoComplete da integrare nella transazione

[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.  
    }  
}  

Vedere anche

Sviluppare applicazioni tramite il modello di servizio WCF