cancel
Showing results for 
Search instead for 
Did you mean: 

Forcing a timeout on an RFC/BAPI call

Former Member
0 Kudos

Hello,

Does anyone know if there is a way to cause a BAPI or RFC call to time out (throwing an exception would be fine) after a specified period of time? We've encountered problems with calls to long running RFC's, through the .net connector, that we'd like to "gracefully" terminate after 60 seconds without a response. By "gracefully" I mean the ability to close the open connection after the timeout.

Any help would be greatly appreciated.

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

There is also a way to call rfcCall, then wait for the answer with rfcListen and when there is an answer ready, call rfcReceive.

The rfcListen returns immediately so you can loop over calls to rfcListen as long as you want to set the timeout.

Edited by: Erez Gordon on Mar 19, 2008 8:54 AM

Former Member
0 Kudos

Hello,

There is not a clean, built-in way to allow an RFC call to really "gracefully" terminate after a specified period of time because neither the underlying RFC library nor the ABAP runtime on the SAP server has a mechanism that makes it possible. In the case of synchronous RFC call (the most developers make RFC calls in this way), there is even no way to forcibly get out of the long running call other than killing the calling thread from another thread.

However, by using the asynchronous methods generated by the .NET Connector wizard, you can simulate such time out behavior and allow your application gracefully "forget" the long running call after the specified period of time. Here is a short description on how to:

1. Select the .sapwsdl file in VS.NET and set the property CreateAsyncs to true;

2. Save the change. For each selected RFC function module, two additional methods for asynchronous calls are added to the proxy by the wizard. For example, you will get BeginMyMethod and EndMyMethod for method MyMethod.

3. Call the methods for asynchronously call and implement the time out:

//construct the proxy instance

SAPProxy1 proxy = new SAPProxy1("your connection string");

//make the call asynchronously

IAsyncResult asyncResult = prxy.BeginMyMethod(..., null, proxy);

//Block the current thread until the call is completed

// or 60 seconds is over

TimeSpan timeout = new TimeSpan(0,0,60);

bool isCompleted = asyncResult.AsyncWaitHandle.WaitOne(timeout ,false);

if(isCompleted) //the call is completed within 60 seconds,

{

proxy.EndMyMethod(asyncResult, ...);

//you are happy with the results

}

else //the call is not yet completed after 10 minutes

{

//just forget the long running call, do whatever you

//like

}

Of course, I assume that the called function module is safe to be forgotten.

Regards,

Guangwei

Former Member
0 Kudos

Guangewei,

Thank you for clarifying this, and for the code sample for calling the RFC asynchronously. This helps.

Regards,

Brian Vandehey