Share this page

# web_service_call

Web Services Functions (SOAP, WEB_SERVICE, Silverlight)

Calls a web service.

    int web_service_call( const char *StepName, [URL,] ExpectedResponse, <List of specifications>, [BEGIN_ARGUMENTS, Arguments, END_ARGUMENTS,] [Send Attachments, ][BEGIN_RESULT, Results, END_RESULT,] [Receive Attachments, ] LAST );

StepName | The name of the step, as it appears in the test tree. Any text can be used.
ExpectedResponse | The type of response to accept. See Expected Response.
URL | The URL (Uniform Resource Locator) of the web service to load.
List of specifications | A comma separated list of the format "Specification=value". For a list, see Specifications.
BEGIN_ARGUMENTS | A marker that indicates the beginning of the ARGUMENTS section.
Arguments | `ArgumentName=Value.` Either the argument name as specified in the WSDL and its assigned value, or one of the User Handler Arguments.
END_ARGUMENTS | A marker that indicates the end of the ARGUMENTS section.
Send Attachments | The attachments to send. For details, see Attachment Specifications.
BEGIN_RESULT | A marker that indicates the beginning of the RESULT section.
Results | `ResultName=ParamName.` The name of result argument or return value as specified in the WSDL, and the name of parameter in which to store the result.
END_RESULT | A marker that indicates the end of the RESULT section.
Receive Attachments | The expected attachments to save when received. For details, see Attachment Specifications.
LAST | A marker that indicates the end of the arguments list.

The web_service_call function calls a web service.

This function is generated when you use the Import WSDL wizard in Web Service Vusers. When you import a WSDL document, by default a web_service_call function is generated.

This is a high-level function that lets you modify all the SOAP arguments intuitively. Because editing the arguments is likely to be error-prone, it is recommended that the function be modified in the tree view rather than in the script editor.

By default, the URL end-point is taken from the WSDL file. Use the URL argument to overwrite (or parameterize) the Web Service end-point.

If you import a web service using the .NET toolkit you may need a web_service_set_option call before the web_service_call in these cases.:

- If the SOAP request message includes WS-Addressing and the WS-Addressing is not required, invoke web_service_set_option("ExcludeWseHeaders", true) before the web_service_call.
- If the SOAP response body is in MIME format, invoke web_service_set_option("HandleMIMEResponse", true) before the web_service_call.
- If the response does not match the ExpectedResponse argument because the server adds security tokens, invoke web_service_set_option("DoNotValidateSecurity", true) before the web_service_call.

## Return Values

This function returns LR_PASS (0) on success, and LR_FAIL (1) on failure. Note that in many cases, this return value indicates the technical success of the function, and not the result. For example, a function that registers a string to be found in a subsequent step returns LR_PASS to indicate that the registration was successful. This does not indicate that the string was found in the server response.

## Parameterization

The URL argument can be parameterized. Most of the values of the specifications can be parameterized. Exceptions are noted in the descriptions below.

### Expected Response

The expected response is one of the following:

Value | Effect
--- | ---
"ExpectedResponse=SoapResult" | Accept SOAP output responses and fail on SOAP faults.
"ExpectedResponse=SoapFault" | Accept SOAP faults and fail on SOAP output responses.
"ExpectedResponse=AnySoap" | Accept both SOAP output and SOAP fault responses.

### Specifications

SOAPMethod: the Web Service method to be called, including the service name, port name, and method name. SOAPMethod cannot be parameterized.

The elements are separated by a period. For example:

SOAPMethod=RPCEncodedEchoService|RPCEncodedEchoServiceSoap|EchoStructContainingArray

RPCEncodedEchoService is the service name.

RPCEncodedEchoServiceSoap is the port name.

EchoStructContainingArray is the method name.

SOAPHeader:an optional custom SOAP header in XML format. The header is enclosed in a SoapHeader tag. For example:

"SOAPHeader=<SoapHeader><element1>some text</element1><element2>some text</element2><element3>some text</element3></SoapHeader>"

Service: the name of the service as defined in WSDL.

WSDL: the location of the WSDL document. WSDL and its arguments cannot be parameterized.

Snapshot: the name of the .inf file containing a snapshot of the step. This argument is recorded. Do not add it when entering the step manually. If it is recorded, do not edit it.

ResponseParam: the name of the output parameter in which to store the server response.

RecordedBuffer: a buffer created during recording that contains the message sent. Do not edit this argument or enter it manually.

ClientEmulation: This argument takes either the name of toolkit (DotNet or Axis) or a recorded keyword, which means that the recorded buffer will be replayed. ClientEmulation is optional. If it is present, it overrides the run time settings.

SOAPAction: The HTTP header as specified in the WSDL.

UseWSDLCopy: This optional argument determines whether the global WSDL or the local copy will be read during the test run. If the value is 1, the local copy is used. If the value is 0, the global WSDL is used. The default is to read the global WSDL.

AsyncEvent: The name of the event to be used in a subsequent call to web_service_wait_for_event. If the web_service_call invocation contains a non-empty AsyncEvent argument, the invocation sends the request and test run continues immediately, without waiting for the response. The run continues until the web_service_wait_for_event call. This argument is optional.

WSAAction: the action to be performed on the destination server.

WSAReplyTo: the IP address to which the response is sent using WS-Addressing. The value is generally a literal IP address of the load generator. When "WSAReplyTo=autodetect" is specified, the IP of the load generator will be detected in runtime. Autodetect requires that service can translate the load generator's host name into IP using a DNS. WS-Addressing is supported in .NET and Axis toolkits. This argument is optional.

JMSSendQueueName: the JNDI name of the send queue. It points to a queue name that can be located by a JNDI lookup operation. This value cannot be empty when using JMS transport. If not using JMS transport, do not pass this argument.

JMSReceiveQueueName: the JNDI name of the receive queue when using JMS transport. It points to a queue name that can be located by a JNDI lookup operation. If this value is missing or empty a temporary queue will be used for receiving. If not using JMS transport, do not pass this argument.

### User Handler Arguments

UserHandlerFunction: The name of a function defined in the script.

UserHandlerName: The name of the user handler and the DLL for handlers defined externally to the script. If you specify a handler function defined in the script as the UserHandlerFunction, then UserHandlerName is ignored.

UserHandlerArgs: A list of configuration arguments for the handler. Use the handler's `GetArguments` method to retrieve the arguments in your handler.

UserHandlerOrder: The order in which the user handler is processed in the request. One of `BeforeSecurity, AfterSecurity`, `AfterAttachments` or `ReplaceTransport`.

For more information about user handlers, see "Customizing Web Service Script Behavior" in the Virtual User Generator Help Center.

## Examples

### Example 1

In the first example, the web_service_call function calls a Web Service GetUKLocationByTown to locate a location on a map.

Copy code

    #include "as_web.h"

    web_service_call( "StepName=UkLocation",
        "ExpectedResponse=AnySoap",
        "URL=http://www.locatorx.net/uklocation.asmx",
        "SOAPMethod=TownService|TownServiceSoap|GetUKLocationByTown",
        "SOAPMethodNamespace=http://www.locatorX.NET",
        "SOAPMethodStyle=document",
        "SOAPAction=http://www.locatorX.NET/GetUKLocationByTown",
        "WSDL=http://www.locatorx.net/uklocation.asmx?WSDL",
        "SOAPHeader=<SoapHeader><e>jb14</e></SoapHeader>",
        "Snapshot=t1.inf",
        BEGIN_ARGUMENTS,
            "Town=London",
        END_ARGUMENTS,
        BEGIN_RESULT,
             "GetUKLocationByTownResult=Result",
        END_RESULT,
        LAST );

### Example 2

In the second example, the web_service_call function performs DIME uploads and downloads.

Copy code

    lr_save_string("Some content for an attachment in a Parameter",
        "pAttachmentContent" );

    // DIME encoded upload
    web_service_call( "StepName=DimeUploadFile_102",
        "ExpectedResponse=AnySoap",
        "SOAPMethod=MyDimeService|MyDimeServiceSoap|DimeUploadFile",
        "SOAPHeader=<SoapHeader><e>jb14</e></SoapHeader>",
        "WSDL=http://myServer/DimeGen/MyDimeService.asmx?WSDL",
        "UseWSDLCopy=1",
        "Snapshot=t1124018494.inf",
        BEGIN_ARGUMENTS,
        "file_name=d:\\temp\\myUploaded.txt",
        END_ARGUMENTS,
        ATTACHMENTS_FORMAT_DIME,
        ATTACHMENT_ADD,
        "FiLeNaMe=d:/temp/attachment.in",//"ContentType=text/plain",
        BEGIN_RESULT,
        END_RESULT,
        LAST );

    // DIME encoded download
    web_service_call( "StepName=DimeDownloadFile_102",
        "SOAPMethod=MyDimeService|MyDimeServiceSoap|DimeDownloadFile",
           "ExpectedResponse=AnySoap",
           "WSDL=http://myServer/DimeGen/MyDimeService.asmx?WSDL",
           "UseWSDLCopy=1",
           "Snapshot=t1124022373.inf",
         BEGIN_ARGUMENTS,
           "file_name=d:\\temp\\myUploaded.txt",
         END_ARGUMENTS,
         BEGIN_RESULT,
         END_RESULT,
         ATTACHMENT_SAVE_ALL,
         "pAraMnAmepReFiX=pAttachmentContent",
         LAST );

### Example 3

In this example, the server reply is directed to a host using WS-Addressing with as specified by the `WSAReplyTo` argument. In the first call, the `WSAAction` is specified. Both calls are asynchronous, as indicated by the `AsyncEvent` argument. The test run continues until the following web_service_wait_for_event invocation.

Copy code

    web_service_call( "StepName=echo_101",
        "ExpectedResponse=AnySoap",
        "SOAPMethod=MyService|MyServiceSOAP12port0|echo",
        "SOAPHeader=<SoapHeader><e>jb14</e></SoapHeader>",
        "ResponseParam=response",
        "Service=MyService",
        "Snapshot=t1156241380.inf",
        "WSAReplyTo=111.111.111.011",
        "WSAAction=http://example1.org/MyServiceSOAP12port0/echo",
        "AsyncEvent=event1",
        BEGIN_ARGUMENTS,
        "xml:part1=<part1><EchoInput>true</EchoInput><Latency>4</Latency></part1>",
        END_ARGUMENTS,
        BEGIN_RESULT,
        "part1/EchoOutput=Param_EchoOutput1",
        END_RESULT,
        LAST );

    web_service_call( "StepName=echo_101",
        "SOAPMethod=MyService|MyServiceSOAP12port0|echo",
        "ResponseParam=response",
        "Service=MyService",
        "Snapshot=t1156241380.inf",
        "WSAReplyTo=111.111.111.011",
        "AsyncEvent=event2",
        BEGIN_ARGUMENTS,
    "xml:part1=<part1><EchoInput>false</EchoInput><Latency>1</Latency></part1>",
        END_ARGUMENTS,
        BEGIN_RESULT,
        "part1/EchoOutput=Param_EchoOutput2",
        END_RESULT,
        LAST );

    web_service_wait_for_event("Quantifier=ALL","Timeout=11111",BEGIN_EVENTS,"event1","event2",END_EVENTS,LAST );

Tips to improve your search results... VuGen Function Reference Version 26.1-26.3 Function Reference 26.1-26.3 All View Local Help Center View Online Help Center Version: