Join Wintertainment 2021 to share your stories, have fun, earn community badges, and more!

OnWebServiceRequest Event

Applies to TestComplete 15.10, last modified on December 07, 2021

Occurs on calling a method of a tested web service.

Declaration

OnWebServiceRequest(SenderRequestHelperRequestInfo) Parameters
Sender [in] Required Variant
Request [in] Required An IXMLDOMDocument object
Helper [in] Required A WebServiceHelper object
RequestInfo [in] Required A WebServiceRequestResponseInfo object

Description

This event occurs when you call a method of your tested web service from a script or keyword test before a request to the web service is made.

You can write the OnWebServiceRequest event handler to perform actions over requests. To access the request content, use the Request parameter of the event handler. You can also add custom SOAP headers to a request by using the Helper parameter.

The event is triggered upon a call to the tested web service method. If in your tests you call several web service methods and you want to process the requests sent only to some of them, use the RequestInfo parameter to determine the name of the called method and the name of the web service to which a request will be sent.

Parameters

The event has the following parameters:

Sender

The Event control that processes the event.

Request

An object implementing the IXMLDOMDocument interface and containing the SOAP request to be sent to the web service. To access and modify data contained in the request, use the properties and methods of the IXMLDOMDocument interface.

For more information on the interface and DOM, see the XML Core Services and Document Object Model article in the MSDN library.

Note: The SOAP request generated by the test engine does not contain the Header element. You can use the WebServiceHelper.AddHeader method to add custom headers.

Helper

A WebServiceHelper helper object that you can use to add custom headers to the SOAP request.

RequestInfo

A WebServiceRequestResponseInfo object that provides information on the tested web service and on the called method.

Remarks

For information on how to create an event handler for this and other TestComplete events, see Creating Event Handlers for TestComplete Events.

Example

The following example demonstrates how to create an OnWebServiceRequest event hander and use it to add custom headers to a web service request:

JavaScript, JScript

// The routine calls methods of the tested web service
function Main()
{

  WebServices.SampleWebService.Authenticate();
  WebServices.SampleWebService.ProcessData();
  …

}

// The OnWebServiceRequest event handler
function GeneralEvents_OnWebServiceRequest(Sender, Request, Helper, RequestInfo)
{

  // Determines the name of the tested web service and the called method
  var methodName = RequestInfo.MethodName;
  var serviceName = RequestInfo.ServiceName;

  if ((serviceName == "SampleWebService") && (methodName == "Authenticate"))
  {
    // Adds custom headers with authentication information to the request
    Helper.AddHeader("UserID", "http://tempuri.org/", "jsmith");
    Helper.AddHeader("Password", "http://tempuri.org/", "25jeL3n");
  }

}

Python

# The routine calls methods of the tested web service
def Main():

  WebServices.SampleWebService.Authenticate()
  WebServices.SampleWebService.ProcessData()
  # ...

# The OnWebServiceRequest event handler
def GeneralEvents_OnWebServiceRequest(Sender, Request, Helper, RequestInfo):

  # Determines the name of the tested web service and the called method
  methodName = RequestInfo.MethodName
  serviceName = RequestInfo.ServiceName

  if ((serviceName == "SampleWebService") and (methodName == "Authenticate")):
    # Adds custom headers with authentication information to the request
    Helper.AddHeader("UserID", "http://tempuri.org/", "jsmith")
    Helper.AddHeader("Password", "http://tempuri.org/", "25jeL3n")

VBScript

' The routine calls methods of the tested web service
Sub Main

  WebServices.SampleWebService.Authenticate
  WebServices.SampleWebService.ProcessData
  …

End Sub

' The OnWebServiceRequest event handler
Sub GeneralEvents_OnWebServiceRequest(Sender, Request, Helper, RequestInfo)

  ' Determines the name of the tested web service and the called method
  methodName = RequestInfo.MethodName
  serviceName = RequestInfo.ServiceName

  If serviceName = "SampleWebService" And methodName = "Authenticate" Then
    ' Adds custom headers with authentication information to the request
    Call Helper.AddHeader("UserID", "http://tempuri.org/", "jsmith")
    Call Helper.AddHeader("Password", "http://tempuri.org/", "25jeL3n")
  End If

End Sub

DelphiScript

// The routine calls methods of the tested web service
procedure Main();
begin

  WebServices.SampleWebService.Authenticate();
  WebServices.SampleWebService.ProcessData();
  …

end;

// The OnWebServiceRequest event handler
procedure GeneralEvents_OnWebServiceRequest(Sender, Request, Helper, RequestInfo);
var methodName, serviceName;
begin

  // Determines the name of the tested web service and the called method
  methodName := RequestInfo.MethodName;
  serviceName := RequestInfo.ServiceName;

  if ((serviceName = 'SampleWebService') and (methodName = 'Authenticate')) then
  begin
    // Adds custom headers with authentication information to the request
    Helper.AddHeader('UserID', 'http://tempuri.org/', 'jsmith');
    Helper.AddHeader('Password', 'http://tempuri.org/', '25jeL3n');
  end;

end;

C++Script, C#Script

// The routine calls methods of the tested web service
function Main()
{

  WebServices["SampleWebService"]["Authenticate"]();
  WebServices["SampleWebService"]["ProcessData"]();
  …

}

// The OnWebServiceRequest event handler
function GeneralEvents_OnWebServiceRequest(Sender, Request, Helper, RequestInfo)
{

  // Determines the name of the tested web service and the called method
  var methodName = RequestInfo["MethodName"];
  var serviceName = RequestInfo["ServiceName"];

  if ((serviceName == "SampleWebService") && (methodName == "Authenticate"))
  {
    // Adds custom headers with authentication information to the request
    Helper["AddHeader"]("UserID", "http://tempuri.org/", "jsmith");
    Helper["AddHeader"]("Password", "http://tempuri.org/", "25jeL3n");
  }

}

See Also

About Testing Web Services
Adding Custom Headers to SOAP Requests
OnWebServiceResponse Event
Handling Events
Event Control

Highlight search results