Share this page

# Record WCF duplex communication

WCF (Windows Communication Foundation) is a programming model that unifies Web Services, .NET Remoting, Distributed Transactions, and Message Queues into a single Service-oriented programming model for distributed computing.

WCF creates a proxy object to provide data for the service. It also marshals the data returned by the service into the form expected by the caller.

In addition to general support for the WCF environment, VuGen provides specialized support for applications that use WCF's duplex communication. In duplex communication, the client proxy contacts the service, and the service invokes the callback handler on the client machine. The callback handler implements a callback interface defined by the server. The server does not have to respond in a synchronous manner—it independently determines when to respond and invoke the callback handler.

Communication between client and server

The communication between the client and server is as follows:

- The server defines the service contract and an interface for the callback.

- The client implements the callback interface defined by the server.

- The server calls the callback handler in the client whenever needed.

When trying to record and replay duplex communication, you may encounter problems when the script calls the original callback methods. By default, the callback handlers are not included in the filter. You could customize the filter to include those callback handlers. However, the standard playback would be ineffective for a load test, since many of the callbacks are local operations such as GUI updates. For an effective load test you cannot replay the original callback method invoked by the server.

VuGen's solution is based on replacing the original callback handler with a dummy implementation. This implementation performs a typical set of actions that you can customize further for your application.

You instruct VuGen to replace the original callbacks by activating the Generate Dummy Callback Handler recording option. For more information, see Microsoft .NET > Recording - Recording options.

VuGen implementation of a duplex callback

As part of the duplex communication solution, VuGen generates two support files:

- `DuplexCallbackHelper.<`language`>`

- Callback_Name`.<`language`>`

The Helper file serves as a general template for working with duplex callback handlers. It serves as a base class for the implementation of the callback.

The second file, Callback_Name, contains the implementation of the callback. The name of the callback implementation class is Vuser<xxxx> where xxxx is the name of the callback interface and it inherits from the VuserDuplexCallbackHelper class defined in the Helper file. VuGen creates separate implementation files for each interface.

This file performs two primary tasks:

- Set Response. It stores the data that came from the server in a map. It stores them with sequential IDs facilitating their retrieval. This method is called from the implementation of the callback interface. The following sample code demonstrates the dummy implementation of a callback method named Result. The method's arguments are stored in the map as an object array.

      public virtual void Result(string operation, double result) {
           // Add here your own callback implementation and set the response data
              SetResponse(responseIndex++, new object[] {
                           operation,
                           result});
      }

- Get Response. Waits for the next response to arrive. The implementation of GetNextResponse retrieves the next response stored in the map using a sequential indexer, or waits until the next response arrives.

The script calls GetNextResponse at the point that the original callback handler was called during recording. At that point, the script prints a warning to wait for here for the next response, and indicating the original callback.

Replacement of the callback in the script

When you enable the Dummy Callback option (enabled by default), VuGen replaces the original duplex callback handlers with dummy implementations. The dummy implementation is called Vuser <Callback Name>. At the point of the original callback handler, the script prints a warning indicating that it was replaced.

Customizing the dummy implementation

You can modify the implementation file to reflect your environment. This section contains several suggested customizations.

Timeouts

The default timeout for which the callback waits for the next response is 60000 msec, or one minute. To use a specific timeout, replace the call to GetNextResponse with the overloading method which gets the timeout as an argument as shown below. This method is implemented in the callback implementation file <Callback_Name> listed in the left pane after the DuplexCallbackHelper file.

    Example:  // Get the next response.
     // This method waits until receiving the response from the server
     // or when the specified timeout is exceeded.

    public virtual object GetNextResponse(int millisecondsTimeout) {
    return base.GetResponse(requestIndex++, millisecondsTimeout);
            }

To change the default threshold for all callbacks, modify the DuplexCallbackHelper file.

    Example:
    // Default timeout threshold while waiting for response
         protected int millisecondsTimeoutThreshold = 60000;

Key Identifier

Many applications assign key identifiers to the data, which connects the request and response to one another. This allows you to retrieve the data from the map using its ID instead of the built-in incremental index. To use a key identifier instead of the index, modify the file <Callback_Name> replacing the first base template parameter, named ID, with the type of your key identifier. For example, if your key identifier is a string you may change the first template argument from int to string:

    public class VuserXXX : VuserDuplexCallbackHelper<string, object>

In addition, you may remove the implementation of GetNextResponse() and replace it with calls to GetResponse(ID) defined in the base class.

Return Values

By default, since VuGen supports OneWay communication, the implementation callback does not return any value or update an output parameter when it is invoked.

    public virtual void Result(string operation, double result) {
       // Add your own callback implementation and set the response data

If your application requires that the callback return a value, insert your implementation at that point.

Get Response Order

In VuGen's implementation, a blocking method waits for each response. This reflects the order of events as they occurred during recording—the server responded with data. You can modify this behavior to execute without waiting for a response or to implement the blocking only after the completion of the business process.

Find Port

The FindPort method in the Helper file is a useful utility that can be used in a variety of implementations. The Helper class uses this method to find unique ports for running multiple instances of the script. You can utilize this utility method for other custom implementations.

Recording server hosted by client applications

If the communication in your system is a server hosted by a client, VuGen's default solution for duplex communication will not be effective. In server hosted by client environments, it is not true duplex communication since the client opens the service and does not communicate through the Framework. For example, in queuing, the client sends a message to the service and opens a response queue to gather the responses.

To emulate a server hosted by a client, use the pattern depicted in the above solution—replace the original response queues with dummy callbacks and perform synchronization as required. For more information, contact Software Support.

Back to top

https://admhelp.microfocus.com VuGen,Professional Performance Engineering,Performance Engineering for Developers 8942
Tips to improve your search results... OpenText™ Virtual User Generator Help Center OpenText™ VuGen Help 25.1-25.3 All View Local Help Center View Online Help Center Version: