Share this page

# User handler examples

This section illustrates several common uses for user handlers.

.NET filters

You can apply a .NET filter to your messages using the user handler mechanism.

If you are familiar with Microsoft's Web Service Enhancements (WSE) 2.0, you can create a .NET filter and register it for incoming or outgoing SOAP messages. A .NET filter is a class that is derived from Microsoft.Web.Services2.SoapInputFilter or Microsoft.Web.Services2.SoapOutputFilter. By overriding the ProcessMessage function of this class, you can examine and modify the envelope's body and header.

To define the filter globally for the entire script, add the following lines to the script's default.cfg file below.

    [UserHandler]
    Function=LrWsSoapFilterLoader
    Args=<Filters InputFilterClass="class name" InputFilterLib="lib name" OutputFilterClass="class name" OutputFilterLib="lib name" />
    Order=BeforeSecurity/AfterSecurity/AfterAttachments

The InputFilterClass parameter indicates the name of your class, and InputFilterLib indicates the name of the assembly in which the class resides. For example:

        web_service_call(
            ...
            "UserHandlerName=LrWsSoapFilterLoader",
            "UserHandlerArgs=<Filters InputFilterClass=\"MyFilterNamespace.MyFilterClassName\" InputFilterLib=\"MyAssemblyName\" />",
            BEGIN_ARGUMENTS,
            ...
            END_ARGUMENTS,
            ...
            );

Use SoapOutputFilter to examine an outgoing web_service_call request, and SoapInputFilter to examine the response from the server. Use InputFilterClass and InputFilterLib if your filter is derived from SoapInputFilter, or OutputFilterClass and OutputFilterLib if your filter is derived from SoapOutputFilter.

To define the filter for a specific step, add the following arguments to the web_service_call function.

    UserHandlerName= LrWsSoapFilterLoader
    UserHandlerArgs=<Filters InputFilterClass=\"class name\" InputFilterLib=\"lib name\" OutputFilterClass=\"class name\" OutputFilterLib=\"lib name\" />
    UserHandlerOrder=BeforeSecurity/AfterSecurity/AfterAttachments

Overriding the transport layer

The following example shows a user handler function overriding the transport layer. VuGen does not automatically send the SOAP request over HTTP transport—instead it follows the transport method indicated in the custom handler.

After you receive a response, set the response envelope with the command:

    lr_save_string(someResponseEnvelopeStr, "SoapEnvelopeParam");

To apply an alternate transport layer, specify ReplaceTransport as a value for the UserHandlerOrder argument. Define the transport layer in the handler.

    web_service_call(..."UserHandlerFunction=<Transport HandlerFunction>", "UserHandlerArgs=<handler arguments>","UserHandlerOrder=ReplaceTransport" ...

    LAST);

Including MIME attachments

When working with Web Service scripts based on the .NET toolkit, the infrastructure does not support MIME attachments. Using the handlers mechanism, you can add MIME attachment functionality to .NET scripts.

The following sections describe how to send and receive MIME attachments for the .NET toolkit. You can receive and send a MIME attachment in the same operation.

Sending MIME attachments

To send a MIME attachment, add the boldfaced code to the web_service_call:

    web_service_call( "StepName=EchoComplex_101",
      "SOAPMethod=SimpleService|SimpleServiceSoap|EchoComplex",
      "ResponseParam=response",
      "Service=SimpleService",
      "UserHandlerName=LrWsAttachmentsHandler",  "UserHandlerArgs=ATTACHMENT_ADD; ATTACHMENTS_FORMAT_MIME;   ContentType=text/plain; FileName=C:\\temp\\results.discomap",
      "ExpectedResponse=SoapResult",
      "Snapshot=t1208947811.inf",
      BEGIN_ARGUMENTS,
      "xml:cls="
       "<cls>"
        "<i>123456789</i>"
        "<s>abcde</s>"
       "</cls>",
      END_ARGUMENTS,
      BEGIN_RESULT,
      END_RESULT,
       LAST);

Modify the FileName and ContentType parameters to indicate the actual path and content type.

Receiving MIME attachments

To receive a MIME attachment, add the following code to the web_service_call:

    "UserHandlerName=LrWsAttachmentsHandler",
     "UserHandlerArgs=ATTACHMENT_SAVE_ALL;ParamNamePrefix=attach;"

Sending and receiving MIME attachments

To send and receive a MIME attachment in the same web_service_call, modify the Web Service call as shown below:

    "UserHandlerName=LrWsAttachmentsHandler",
     "UserHandlerArgs=ATTACHMENT_SAVE_ALL;ParamNamePrefix=attach; ATTACHMENT_ADD; ATTACHMENTS_FORMAT_MIME; ContentType=text/plain; FileName=C:\\temp\\results.discomap",

Back to top

See also:

- User handlers
- Create a user handler

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 26.1 All View Local Help Center View Online Help Center Version: