Web Service Consumer - MuleSoft Documentation PDF
Web Service Consumer - MuleSoft Documentation PDF
When developing applications with Mule, users often need to consume a SOAP Web service to
acquire data from an external source. In the best case scenario, you can use an existing
Anypoint Connector in your Mule application to connect to a speci c service provider, such as
Zuora or Avalara. However, where no service-speci c connector exists to facilitate the
connection, the quickest, easiest way to consume a Web service from within a Mule
application is to use the Web Service Consumer.
Using the information contained in a service’s WSDL, this connector enables you to con gure
a few details to establish the connection you need to consume a service from within your
Mule application. Identify the location of the Web service’s WSDL le, then ask the Web
Service Consumer to con gure itself from the WSDL to get the host, port, and address.
Before this component existed in Studio, you may have con gured an HTTP connector and
SOAP Component in a Mule ow to be able to consume a Web service; now you can simply
insert the Web Service Consumer connector into your ow, requiring less e ort to con gure.
The Web Service Consumer also o ers extra functionality to help you build out your
application:
With a DataWeave transformer, the Web Service Consumer makes use of DataSense
functionality to acquire information about the expected format and structure of the input
or output, so as to eliminate the guesswork in trying to gure out what to send to, and
what to receive from, a SOAP Web service.
With a DataWeave transformer, you can visually map the input you receive (SOAP header
or body) into another data format or structure for further processing.
https://docs.mulesoft.com/mule-runtime/3.9/web-service-consumer 1/27
5/3/2020 Web Service Consumer | MuleSoft Documentation
Secure your Web service requests using the functionality embedded within the Web Service
Consumer to add a username token to requests, and/or WS-Security timestamp.
For example, imagine you wish to build an application in which you need to gather
information about the last price at which a stock traded. After accepting an end-user request,
you need to consume an external SOAP Web service that checks for the most recent trade of
a particular stock, and the price at which it sold, then returns a response. Such an application
could make use of the Web Service Consumer to consume the stock quote information, and
then use a DataWeave to map the results to a format that could be returned to the end-user.
See rst gure below; a second example follows below it.
The component formerly known as the SOAP Connector is now known as the CXF
Component. It should not be confused with the Web Service Consumer.
Prerequisites
https://docs.mulesoft.com/mule-runtime/3.9/web-service-consumer 2/27
5/3/2020 Web Service Consumer | MuleSoft Documentation
This document assumes that you are familiar with SOAP, WSDLs, DataWeave, Mule, Anypoint
connectors, Anypoint Studio essentials, elements in a Mule ow, and global elements.
When Studio has an update, a message displays in the lower right corner, which you can click
to install the update.
Limitations
The Web Service Consumer interfaces only with SOAP Web services, not REST APIs.
Within Mule, the Web Services Consumer is available for use only in conjunction with the
following connectors:
File
FTP
HTTP
HTTPS
JMS
SFTP
The Web Service Consumer cannot handle multipart SOAP requests. If a multipart SOAP
request is submitted, this error occurs: Operation Messages With More Than 1 Part Are Not
Supported.
To solve this, modify the WSDL to remove the header parts and continue using the Web
Service Consumer. Alternatively, you can use the CXF module to call the service.
1. Add the WSDL le of the service you want to consume to your Mule project.
4. Add a Connector Con guration using the green plus sign you see in the properties window
of the Web Service Consumer element you added to your ow.
5. In the Global Web Service Consumer element, specify the location of the web service’s
WSDL, and apply any security settings that the service provider demands. To take
advantage of the design-time power of the Web Service Consumer, consider using it in
conjunction with DataWeave using the Transform Component.
For more information on best design-time practices with DataSense and DataWeave, see the
DataSense documentation.
https://docs.mulesoft.com/mule-runtime/3.9/web-service-consumer 4/27
5/3/2020 Web Service Consumer | MuleSoft Documentation
Example:
<ws:consumer-config name="Web_Service_Consumer"
service="TestService" port="TestPort" serviceAddress="http://fake.com/services/Test"
wsdlLocation="http://fake.com?Wsdl"
useConnectorToRetrieveWsdl="true" />
When designing your application in Studio, when you drag the connector from the palette to
the Anypoint Studio canvas, Studio automatically populates the XML code with the connector
namespace and schema locations.
Namespace: xmlns:ws="http://www.mulesoft.org/schema/mule/ws"
Schema Location: http://www.mulesoft.org/schema/mule/ws/current/mule-ws.xsd
If you are manually coding the Mule application in Studio’s XML editor or other text editor,
de ne the namespace and schema location in the header of your Con guration XML, inside
the <mule> tag.
https://docs.mulesoft.com/mule-runtime/3.9/web-service-consumer 5/27
5/3/2020 Web Service Consumer | MuleSoft Documentation
http://www.mulesoft.org/schema/mule/core
http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/ws
http://www.mulesoft.org/schema/mule/ws/current/mule-ws.xsd
http://www.mulesoft.org/schema/mule/successfactors
http://www.mulesoft.org/schema/mule/successfactors/current/mule-successfactors.xsd
http://www.mulesoft.org/schema/mule/http
http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">
https://docs.mulesoft.com/mule-runtime/3.9/web-service-consumer 6/27
5/3/2020 Web Service Consumer | MuleSoft Documentation
1. Begin by acquiring the WSDL le for the SOAP Web service you intend to consume, or
identify the URL of the WSDL. You can also open a WSDL le from Anypoint Exchange by
clicking the Exchange icon on the left of the Studio task bar.
2. If you are using a WSDL le, copy the le into the src/main/resources folder of your Studio
project. (You can drag and drop the le to copy it to the folder.) If using a URL, there is no
need to copy anything to your Studio project.
3. Drag a Web Service Consumer connector into a ow in your application. Click the Web
Service Consumer icon to open its Properties Editor, then change the default value of the
Display Name of the connector, if you wish.
4. De ne the Global Con guration of the connector by clicking the plus sign next to the Global
Con guration eld.
5. In the window that opens, enter a value in the WSDL Location eld. Populate this eld rst.
To do this:
Click the link Search WSDL in Exchange to open the Anypoint Exchange and select a WSDL de nition
residing there.
Click the … button to provide a lepath and lename of the WSDL le you copied into the
src/main/resources folder of your project.
Upon lling out this eld, you give Studio the opportunity to read the contents of the WSDL and
automatically populate the remaining empty elds — Service , Port , and Address — using
information contained in the WSDL le. Alternatively, you can manually populate these elds with the
appropriate information about the Web service. If a Port value is not present, click the down arrow to
choose a value.
https://docs.mulesoft.com/mule-runtime/3.9/web-service-consumer 7/27
5/3/2020 Web Service Consumer | MuleSoft Documentation
6. If Enable DataSense box is available in your version of Web Service Consumer, con rm its
box is checked, then click OK to save.
7. Notice that Studio auto-populates the following elds in the Properties Editor of the Web
Service Consumer element in your ow:
Connector Con guration - With the name of the Global Web Service Consumer that you just created.
Operation - With the name of an operation that the Web service supports for its consumers. Click the
down-arrow to choose an operation.
8. De ne the Operation of the Web Service Consumer, if you wish (and if the SOAP Web
service o ers more than one operation), then save your con guration.
https://docs.mulesoft.com/mule-runtime/3.9/web-service-consumer 8/27
5/3/2020 Web Service Consumer | MuleSoft Documentation
NOTE
As with the CXF component, you can optimize transmission of SOAP messages using the Message
Transmission Optimization Mechanism (MTOM) by checking the MTOM Enabled box, or by de ning
an expression that triggers MTOM activation. See Using MTOM.
1. Acquire a WSDL le for the SOAP Web service you intend to consume, or identify the URL of
the WSDL.
2. If you are using a WSDL le, copy the le into the src/main/resources folder of your Studio
project. (You can drag and drop the le to copy it to the folder.) If using a URL, there is no
need to copy anything to your Studio project.
3. Above all the ows in your application, add a global ws:consumer-config element to your
application. Con gure its attributes according to the code sample below to de ne how to
connect to the Web service you intend to consume. For a full list of elements, attributes
and default values, consult the Web Service Consumer Reference.
https://docs.mulesoft.com/mule-runtime/3.9/web-service-consumer 9/27
5/3/2020 Web Service Consumer | MuleSoft Documentation
Con gure its attributes according to the code sample below to de ne the global Web
Service Consumer to reference, and the operation to perform with a request to the Web
service. For a full list of elements, attributes and default values, see the Web Service
Consumer Reference.
If DataWeave follows the fully-con gured Web Service Consumer, DataWeave has access to
its input values and you can use these as inputs to create your custom output.
If DataWeave precedes the fully-con gured Web Service Consumer, DataWeave creates a
sca olding that produces an output that matches what the Web Service Consumer expects
to receive (see below).
{
"item_amount": "????",
"payment": {
"currency": "????",
"installments": "????",
"payment-type": "????"
},
"product": {
"model": "????",
"price": "????"
},
"salesperson": "????",
"shop": "????"
}
https://docs.mulesoft.com/mule-runtime/3.9/web-service-consumer 10/27
5/3/2020 Web Service Consumer | MuleSoft Documentation
To take advantage of Web Service Consumer, DataSense, and DataWeave, con gure these
elements in the following order:
2. The Web Service Consumer connector in a ow in your application, which references the
Global Web Service Consumer connector.
3. The Transform Message (DataWeave transformer), dropped before or after the Web
Service Consumer connector in your ow.
WARNING
Outbound properties that begin with a soap. pre x are treated as SOAP headers and ignored by
the transport. All properties that aren’t named with a soap. pre x are treated as transport headers
(by default, the WSC uses the HTTP transport).
https://docs.mulesoft.com/mule-runtime/3.9/web-service-consumer 11/27
5/3/2020 Web Service Consumer | MuleSoft Documentation
WARNING
When con guring the header manually, the value you pass should have the structure of an XML
element, and it shouldn’t be a plain pair of key and value. Using a set property element, for example,
the value of the property must contain the enclosing XML tags, like so:
<set-property propertyName="soap.Authorization"
value="<auth>Bearer
MWYxMDk4ZDktNzkyOC00Z</auth>"/>
1. Ensure you have con gured a DataSense-enabled Web Service Consumer in your ow and
set a DataWeave transformer to follow it. Click the DataWeave icon in the canvas to open
its Properties Editor.
2. If the SOAP service returns a response with headers, the tree in the input section of the
DataWeave transformer has multiple inbound properties in it. Each header enters the Mule
ow as an inbound property. You can double click it to open this property in a di erent tab
and provide test data.
3. In the transform’s input directives you can see how this input is being referenced, use this
as part of the path when refering to one of the elements in the header.
TIP
With DataWeave, you can use multiple inputs in a single transform, so you can take information from
both the SOAP body and the SOAP headers to produce your output.
https://docs.mulesoft.com/mule-runtime/3.9/web-service-consumer 12/27
5/3/2020 Web Service Consumer | MuleSoft Documentation
To produce multiple outputs, you must create separate transforms, but these can be hosted in a
single DataWeave transformer on your ow. So in a single DataWeave transformer you could host a
transform that populates the SOAP body and another that populates a SOAP header.
Use the DataSense Explorer feature in Studio to gain design-time insight into the state of the
message payload, properties, and variables as it moves through your ow. The DataSense
Explorer is mostly useful in understanding the content of a message before it encounters a
Web Service Consumer, and after it emerges from the connector so as to better understand
the state of the data your application is working with.
The DataSense Explorer in the example below o ers information about the Payload,
Variables, Inbound Properties and Outbound Properties contained that comprise the
message object at the moment the message encounters the Web Service Consumer. Use the
In-Out toggle at the top of the DataSense Explorer to view metadata of message as it arrives
at, or leaves the message processor.
https://docs.mulesoft.com/mule-runtime/3.9/web-service-consumer 13/27
5/3/2020 Web Service Consumer | MuleSoft Documentation
To proxy the request to the SOAP service, go to the Global Elements tab in Studio, create a
new HTTP Request global element, and from the Proxy tab of the HTTP Request
Con guration, enter the host and port details of the proxy.
https://docs.mulesoft.com/mule-runtime/3.9/web-service-consumer 14/27
5/3/2020 Web Service Consumer | MuleSoft Documentation
Specify your newly created proxy con guration from the Reference tab of the global element
for the Web Service Consumer.
https://docs.mulesoft.com/mule-runtime/3.9/web-service-consumer 15/27
5/3/2020 Web Service Consumer | MuleSoft Documentation
The proxy con guration looks similar to this XML block in your Mule application:
<mule xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw"
xmlns:metadata="http://www.mulesoft.org/schema/mule/metadata"
xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml"
xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking"
xmlns:ws="http://www.mulesoft.org/schema/mule/ws"
xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
https://docs.mulesoft.com/mule-runtime/3.9/web-service-consumer 16/27
5/3/2020 Web Service Consumer | MuleSoft Documentation
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core
http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/ws
http://www.mulesoft.org/schema/mule/ws/current/mule-ws.xsd
http://www.mulesoft.org/schema/mule/http
http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ee/tracking
http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
http://www.mulesoft.org/schema/mule/ee/dw
http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd
http://www.mulesoft.org/schema/mule/xml
http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd">
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0"
port="8082" doc:name="HTTP Listener Configuration"/>
<ws:consumer-config name="Web_Service_Consumerweather"
wsdlLocation="http://www.webservicex.com/globalweather.asmx?WSDL"
service="GlobalWeather"
port="GlobalWeatherSoap"
serviceAddress="http://www.webservicex.com/globalweather.asmx"
doc:name="Web Service Consumer"/>
<http:request-config name="HTTP_Request_Configuration" host="www.webservicex.com"
port="80" doc:name="HTTP Request Configuration">
<http:proxy host="example.proxy.com" port="8080"/>
</http:request-config>
<flow name="soap-wsc-proxy">
<http:listener config-ref="HTTP_Listener_Configuration" path="/country" doc:name="HTTP"/
<set-variable variableName="CountryName"
value="#[message.inboundProperties.'http.query.params'.CountryName]"
doc:name="Get Cities by Country"/>
<dw:transform-message doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/xml
%namespace ns0 http://www.webserviceX.NET
---
{
ns0#GetCitiesByCountry: {
ns0#CountryName: flowVars.CountryName as :string
}
}]]></dw:set-payload>
</dw:transform-message>
<ws:consumer config-ref="Web_Service_Consumerweather" doc:name="Web Service Consumer" op
<logger level="INFO" doc:name="Logger"/>
</flow>
</mule>
https://docs.mulesoft.com/mule-runtime/3.9/web-service-consumer 17/27
5/3/2020 Web Service Consumer | MuleSoft Documentation
1. Within the Global Web Service Consumer element’s Global Element Properties panel, click
the Security tab:
https://docs.mulesoft.com/mule-runtime/3.9/web-service-consumer 18/27
5/3/2020 Web Service Consumer | MuleSoft Documentation
2. Based on the security requirements of the Web service provider, select to apply Username
Token security, or a WS-Security Timestamp or both.
TIP
For a full list of elements, attributes and default values, see the Web Service Consumer Reference.
...
<ws:consumer-config name="OrderWS" wsdlLocation="enterprise.wsdl.xml" service="OrderService"
<ws:security>
<ws:wss-username-token username="test" password="test" passwordType="DIGEST" addCrea
https://docs.mulesoft.com/mule-runtime/3.9/web-service-consumer 19/27
5/3/2020 Web Service Consumer | MuleSoft Documentation
<ws:wss-timestamp expires="30000"/>
</ws:security>
</ws:consumer-config>
...
You can determine the freshness of the response’s security semantics to your WS request by
instructing Mule to verify the response’s timestamp using the
mule.ws.checkWssResponseTimestamp attribute:
You can set it when starting Mule passing the following argument:
-M-Dmule.ws.checkWssResponseTimestamp=true
wrapper.java.additional.<n>=-mule.ws.checkWssResponseTimestamp=true
TIP
Learn more about passing JVM arguments to your Mule instance here.
http://myUserName:myPassword@hostService
https://docs.mulesoft.com/mule-runtime/3.9/web-service-consumer 20/27
5/3/2020 Web Service Consumer | MuleSoft Documentation
By default, the WSC consumer runs over a default con guration for the HTTP Request
Connector. If you need it to instead run over a con guration of the connector that uses HTTPS
(or an HTTP con guration that is di erent from the default) follow the steps below:
1. Click the Global Elements tab, below the canvas and create a new Global Element
2. For the Global Element type, select HTTP Request Con guration
3. Complete the required elds in the General tab (host and port)
4. Then select the TLS/SSL tab and con gure the elds related to the HTTPS authentication,
Default or Custom.
5. In your instance of the Web Service Consumer in your ow, click on the green plus sign
next to Connector Con guration.
https://docs.mulesoft.com/mule-runtime/3.9/web-service-consumer 21/27
5/3/2020 Web Service Consumer | MuleSoft Documentation
6. In the References tab, select your newly created HTTPS Global Element for the Connector
Ref eld.
By default, the WSC consumer runs over a default con guration for the HTTP Request
Connector. If you need it to instead run over a con guration of the connector that uses HTTPS
https://docs.mulesoft.com/mule-runtime/3.9/web-service-consumer 22/27
5/3/2020 Web Service Consumer | MuleSoft Documentation
(or an HTTP con guration that is di erent from the default) follow the steps below:
1. Add an HTTP Connector global element in your project, con gure it with the necessary
security attributes
<ws:consumer-config
name="Web_Service_Consumer"
wsdlLocation="tshirt.wsdl.xml"
service="TshirtService"
port="TshirtServicePort"
serviceAddress="http://tshirt-service.qa2.cloudhub.io/tshirt-service"
connectorConfig="HTTP_Request_Configuration"/>
If none of the two reference attributes are speci ed, a default instance of the new HTTP
connector is used. For backwards compatibility, you can change this behavior and make an
instance of the deprecated HTTP Transport the default con guration. There’s a global
con guration property that has been added in Mule runtime 3.6, that allows you to change
this default behavior:
<configuration>
<http:config useTransportForUris="true"/>
https://docs.mulesoft.com/mule-runtime/3.9/web-service-consumer 23/27
5/3/2020 Web Service Consumer | MuleSoft Documentation
</configuration>
The deafult value for this attribute is false. When setting this ag to true, Mule falls back to the
deprecated HTTP transport to resolve URIs when no transport/connector is speci ed.
XML View
https://docs.mulesoft.com/mule-runtime/3.9/web-service-consumer 24/27
5/3/2020 Web Service Consumer | MuleSoft Documentation
---
{
}]]></dw:set-payload>
</dw:transform-message>
</flow>
</mule>
See Also
Learn more about how to use the DataWeave transformer.
Edit on GitHub
https://docs.mulesoft.com/mule-runtime/3.9/web-service-consumer 26/27
5/3/2020 Web Service Consumer | MuleSoft Documentation
Email >
Developers Blog Terms Privacy Privacy Shield Cookie preferences Contact 1-415-229-2009
MuleSoft provides a widely used integration platform for connecting applications, data, and devices in the cloud and on-premises. MuleSoft's
Anypoint Platform™ is a unified, single solution for iPaaS and full lifecycle API management. Anypoint Platform, including CloudHub™ and Mule
ESB™, is built on proven open-source software for fast and reliable on-premises and cloud integration without vendor lock-in.
https://docs.mulesoft.com/mule-runtime/3.9/web-service-consumer 27/27