---
schema_version: "1"
id: 117402862574fad030cdc06b3e37b5012dcd0a2ffbe7d8eafd5ccf1244c92f70
title: Web Service Consumer - Example 1
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/web-service-consumer-connector/latest/web-service-example-1.md
canonical_url: https://docs.mulesoft.com/web-service-consumer-connector/latest/web-service-example-1
source_site: docs.mulesoft.com
content_type: documentation
content_hash: d5be2d11e39d69630e6259f28e78ed18d1f067eed731faa563020f1ae24f741e
description: MuleSoft Documentation Site
release: "2.2"
latest: true
---
---
product: Web Service Consumer Connector
version: 2.2
is-latest-version: true
---

# Web Service Consumer - Example 1

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

The following example shows how to transform a variable value into XML and pass that value to
Anypoint Connector for Web Service Consumer (Web Service Consumer Connector), which subsequently
consumes a web service:

![Web Service Consumer Example Flow in Studio Canvas](/mulesoft/current/en-us/web-service-consumer-connector/latest/_images/web-service-consumer-example1.png)

## Create the Mule App in Anypoint Studio

To create the flow in Anypoint Studio:

1.  In the **Mule Palette** view, select **Core** > **Scheduler**.

2.  Drag the **Scheduler** component to the Studio canvas.  
    The **Scheduler** component initiates a flow when a time-based condition is met.

3.  Set the **Display Name** field to `Scheduler`.

4.  Set **Scheduling Strategy** to `Fixed Frequency`, **Frequency** to `1000`, **Start delay** to
    `0` and **Time unit** to `MILLISECONDS (Default)`.

In Studio, the **Scheduler** configuration looks like this:

![Scheduler Configuration](/mulesoft/current/en-us/web-service-consumer-connector/latest/_images/web-service-consumer-example2.png)

Figure 1. Scheduler Configuration

5.  Drag a **Set Variable** component onto the canvas, to the right of the **Scheduler**
    component.  
    The **Set Variable** component creates the variable to be transformed into XML later in the
    flow.

6.  Set the **Display Name** field to `Set Variable`.

7.  Set **Name** to `variableSample` and **Value** to `test`.

In Studio, the **Set Variable** configuration looks like this:

![Set Variable Configuration](/mulesoft/current/en-us/web-service-consumer-connector/latest/_images/web-service-consumer-example3.png)

Figure 2. Set Variable Configuration

8.  Drag a **Transform Message** component onto the canvas, to the right of the **Set Variable**
    component.  
    The **Transform Message** component transforms the variable value into XML.

9.  In the **Output** field of the **Transform Message** component configuration, set a DataWeave
    expression that:

    - Transforms the variable value output to `application/xml`.

    - Defines the name of the web service operation that the Web Service Consumer Connector aims to
      invoke by `attachOperation`.

DataWeave Expression

```xml
%dw 2.0
output application/xml
ns con http://service.soap.service.mule.org/
---
con#attachOperation: {
   text: vars.variableSample
}
```

In Studio, the **Transform Message** configuration looks like this:

![Transform Message Configuration](/mulesoft/current/en-us/web-service-consumer-connector/latest/_images/web-service-consumer-example4.png)

Figure 3. Transform Message Configuration

10. Drag the **Consume** operation onto the canvas, to the right of the **Transform Message**
    component.

11. Set the **Display Name** field to `Consume`.

12. Set **Operation** to `attachOperation` and the **Body** message to `payload`.

13. In the **Message Customization** section of the **Advanced** tab, enable the option **Force XML
    Prolog into body** to append the XML prolog to the content of the envelope’s body XML.

In Studio, the **Consume** operation configuration looks like this:

![Consume Operation Configuration](/mulesoft/current/en-us/web-service-consumer-connector/latest/_images/web-service-consumer-example5.png)

Figure 4. Consume Operation Configuration

In Studio, the **XML Prolog** configuration looks like this:

![Configure XML Prolog into Body](/mulesoft/current/en-us/web-service-consumer-connector/latest/_images/web-service-consumer-xmlprolog.png)

Figure 5. Configure XML Prolog into Body

14. On the **General** tab, click the plus sign (+) next to the **Connector configuration** field to
    access the **Global Element Properties** configuration.

15. On the **Connection** section of the **General** tab, configure the following parameters:

    - **WSDL location**  
      The remote or local WSDL file URL

    - **Service**  
      The service name

    - **Port**  
      The port name

    - **Address**  
      The address of the web server to dispatch requests but if the **Service** and **Port**
      parameters don’t auto-populate the web server address, you must manually provide the correct
      **Address**.

16. Click **OK**.

In Studio, the **Global Element Properties** configuration looks like this:

![Web Service Consumer Configuration](/mulesoft/current/en-us/web-service-consumer-connector/latest/_images/web-service-consumer-example6.png)

Figure 6. Web Service Consumer Configuration

17. Save your changes in Studio.

18. Deploy the application.

## XML for Consuming a Web Service

Paste this code into the Studio XML editor to quickly load the flow for this example into your Mule
app:

```xml
<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xmlns:wsc="http://www.mulesoft.org/schema/mule/wsc"
	xmlns="http://www.mulesoft.org/schema/mule/core"
	xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/wsc http://www.mulesoft.org/schema/mule/wsc/current/mule-wsc.xsd
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
	<wsc:config name="Web_Service_Consumer_Config">
		<wsc:connection wsdlLocation="api/attach-demo.wsdl" service="AttachDemo" port="AttachDemoSOAP" address="http://localhost:8085/AttachDemo/AttachDemoSOAP" />
	</wsc:config>
	<flow name="WSC-Example">
		<scheduler>
			<scheduling-strategy >
				<fixed-frequency />
			</scheduling-strategy>
		</scheduler>
		<set-variable value="test" variableName="variableSample"/>
		<ee:transform>
			<ee:message >
				<ee:set-payload ><![CDATA[ %dw 2.0
output application/xml
ns con http://service.soap.service.mule.org/
---
con#attachOperation: {
    text: vars.variableSample
}]]></ee:set-payload>
			</ee:message>
		</ee:transform>
		<wsc:consume config-ref="Web_Service_Consumer_Config" operation="attachOperation">
			<wsc:message-customizations forceXMLProlog="true"/>
		</wsc:consume>
	</flow>
</mule>
```
