[go: up one dir, main page]

0% found this document useful (0 votes)
437 views27 pages

Web Service Consumer - MuleSoft Documentation PDF

Uploaded by

rithuik1598
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
437 views27 pages

Web Service Consumer - MuleSoft Documentation PDF

Uploaded by

rithuik1598
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

5/3/2020 Web Service Consumer | MuleSoft Documentation

Product Solutions Services


Developers Resources
Partners Company

Contact Free trial Login

Web Service Consumer


Prerequisites ▾

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.

To Install this Connector


1. In Anypoint Studio, click the Exchange icon in the Studio taskbar.

2. Click Login in Anypoint Exchange.

3. Search for the connector and click Install.

4. Follow the prompts to install the connector.

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.

The following is an example of the incorrect multipart use:

<soap:header message="sws:MyInput" part="header" use="literal"/>


<soap:header message="sws:MyInput" part="header2" use="literal"/>
<soap:body parts="body" use="literal"/>
https://docs.mulesoft.com/mule-runtime/3.9/web-service-consumer 3/27
5/3/2020 Web Service Consumer | MuleSoft Documentation

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.

Basic Usage of Web Service Consumer


To use a Web Service Consumer in your Mule application, you must carry out three tasks:

1. Add the WSDL le of the service you want to consume to your Mule project.

2. Add a Web Service Consumer element to your Mule ow.

3. De ne the Operation to perform.

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 about DataWeave and DataSense:

DataSense: The Web service consumer is DataSense-compatible. DataSense uses


information in the WSDL to automatically extract metadata about the data structure and
format a SOAP Web service delivers or expects. When this functionality is enabled (in the
global con guration of the Web Service Consumer element or by default in newer
versions), the type of data that is sent or expected by the service is easily discoverable.

DataWeave transformer: When used in conjunction with a DataSense-enabled Web Service


Consumer, DataWeave can automatically extract payload or header metadata from the
service that you can map and transform through a visual interface. For example, if you
con gure a Web Service consumer in your application, then drag a DataWeave transformer
after it, DataWeave uses the information that DataSense extracted to pre-populate the
input values for mapping, so that you only need to con rm (or adjust) the selections, then
proceed to mapping to your desired output. In other words, DataSense makes sure that
DataWeave knows the data format and structure with which it must work so you don’t have
to gure it out manually.

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

To Use HTTP Requester to Obtain a WSDL from


XML
In Mule 3.9 and later, you can use the useConnectorToRetrieveWsdl attribute in XML. This
attribute uses the HTTP Requester provided by the Connector Con guration to obtain a
WSDL. The WSDL Location must be at an HTTP or HTTPS URL location.

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" />

Namespace and Schema for XML


The following sections provide namespace and schema information.

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.

Example Mule app header - <mule> tag

<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:successfactors="http://www.mul


xmlns:ws="http://www.mulesoft.org/schema/mule/ws"
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"
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

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">

Configuring the Web Service Consumer


To prepare an application to use a Web Service as in one of the examples above, you must
rst add the Web service’s WSDL to your Mule project, then con gure, at minimum, the
required parameters for the Web Service Consumer element and a Global Web Service
Consumer element. The diagram and section below describes how to address these
requirements.

https://docs.mulesoft.com/mule-runtime/3.9/web-service-consumer 6/27
5/3/2020 Web Service Consumer | MuleSoft Documentation

Configure WSC with the Studio Visual Editor

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.

Type the WSDL’s URL in the eld.

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.

Configure WSC with the XML Editor


To con gure the connector:

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.

<ws:consumer-config name="Web_Service_Consumer1" wsdlLocation="src/main/resources/sample_wsdl

4. Add a ws:consumer element to a ow in your application.

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.

<ws:consumer doc:name="Web Service Consumer" config-ref="Web_Service_Consumer1" operation="Ge

Web Service Consumer and DataWeave


As stated above, when used in conjunction with a DataSense-enabled Web Service Consumer,
DataWeave automatically extracts the payload or header metadata that you can use to map
and or transform to a di erent data format or structure through the DataWeave language.
When you have a con gured, DataSense-enabled Web Service Consumer in your ow, you
can drop a DataWeave transformer next to it – preceding or following it – and DataWeave
automatically extracts the information that DataSense collected from the WSDL about the
expected format and structure of the message.

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:

1. The Global Web Service Consumer element, with DataSense enabled.

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.

Adding Custom Headers


Create SOAP headers as outbound properties through the Property transformer.

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).

Add Custom Headers with the Studio Visual Editor

Add Custom Headers with the XML Editor

https://docs.mulesoft.com/mule-runtime/3.9/web-service-consumer 11/27
5/3/2020 Web Service Consumer | MuleSoft Documentation

<set-property propertyName="soap.myProperty" value="#[payload]" doc:name="Property"/>

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>"/>

The example above works, the one below doesn’t:

<set-property propertyName="soap.Authorization" value="Bearer


MWYxMDk4ZDktNzkyOC00Z"/>

Mapping SOAP Headers


With a Web Service Consumer, DataWeave o ers the option of mapping and transforming a
message’s payload, properties, or variables by picking di erent inputs.

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.

Web Service Consumer and DataSense


Explorer
Menu Mule Runtime Mule Runtime 3.x Reference Anypoint Connectors Web Service Consumer

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.

Message State Before Web Service Consumer

Message State After Web Service Consumer

https://docs.mulesoft.com/mule-runtime/3.9/web-service-consumer 13/27
5/3/2020 Web Service Consumer | MuleSoft Documentation

Proxy the Web Service Consumer


This section describes how to con gure a proxy request to the SOAP service in a Mule
application. Let’s start with this ow that grabs a country name as an HTTP parameter and
stores it in a variable for the SOAP service request to a weather data service that displays all
cities for which data for the country is given.

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:

<http:request-config name="HTTP_Request_Configuration" host="www.webservicex.com"


port="80" doc:name="HTTP Request Configuration">
<http:proxy host="my.example.proxy.com" port="8080"/>
</http:request-config>

The example ow:

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

<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

Securely Connecting to a SOAP Web Service


Depending upon the level of security employed by a SOAP Web service, you may need to
correspondingly secure the requests your Web Service Consumer sends. Any calls you send to
a Web service have to adhere to the Web service provider’s security requirements. To comply
with this requirement, you can con gure security settings on your Global Web Service
Consumer connector.

The WSC allows you to:

Add an expiration to messages

Add username and password header to outgoing messages

Add a signature header to outgoing messages

Verify incoming messages for signature headers

Encrypt outgoing messages (at SOAP level)

Decrypt incoming messages (at SOAP level)

Securely Connect Using the Studio Visual Editor


To securely connect:

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.

3. Enter values in the required elds.

TIP

For a full list of elements, attributes and default values, see the Web Service Consumer Reference.

4. Click OK to save your security settings.

Securely Connect Using the XML Editor


Add child elements to the global ws:consumer-con g element you con gured in your
application. Con gure the child elements' attributes according to the code sample below. For
a full list of elements, attributes and default values, consult 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>
...

Verify the Response Timestamp


Not all web services provide a timestamp in their responses. You need to verify this with the
security requirements of your Web Service Provider.

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

Or you can set it as a wrapper con guration in your ${MULE_HOME}/conf/wrapper.conf le:

wrapper.java.additional.<n>=-mule.ws.checkWssResponseTimestamp=true

TIP
Learn more about passing JVM arguments to your Mule instance here.

Using Basic Authentication and SSL


If the web service you’re connecting to requires basic authentication, you can easily provide
your username and password as part of the URL when you reach out to it.

The URL should follow the structure below:

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

In the Web Service Consumer’s Global Element, add a reference to an http-request-config


element.

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.

Configure Authentication Using the Studio Visual


Editor
To con gure:

1. Enter the Web Service Consumer’s global con guration element.

2. Open the References tab.

3. Create a new reference by clicking the green plus sign.

Configure Authentication Using the XML Editor

<http:request-config host="localhost" port="${port}" name="customConfig">


<http:basic-authentication username="user" password="pass" />
</http:request-config>

<ws:consumer-config wsdlLocation="Test.wsdl" service="TestService" port="TestPort" serviceAd

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

<http:request-config name="HTTP_Request_Configuration" host="example.com"


port="8081" protocol="HTTPS" doc:name="HTTP_Request_Configuration"/>
<tls:context>
<tls:trust-store path="your_truststore_path" password="your_truststore_password"/
<tls:key-store path="your_keystore_path" password="your_keystore_path" keyPasswor
</tls:context>
</http:request-config>

2. In your ws:consumer-config element, include a connectorConfig attribute to reference to this


HTTP connector con guration element:

<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"/>

Referencing the Deprecated HTTP Transport


To set alternate HTTP settings, instead of referencing an instance the new HTTP Connector,
you can reference an instance of the deprecated HTTP transport and accomplish the same. To
add this reference, add a connector-ref attribute to the WSC con guration element. The
connectorConfig and connector-ref attributes are mutually exclusive, and both optional.

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.

Complete Code Example


Visual Studio Editor View

XML View

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


<mule xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" xmlns:file="http://www.mulesoft.org/s
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.o
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.x
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-h
http://www.mulesoft.org/schema/mule/ws http://www.mulesoft.org/schema/mule/ws/current/mule-ws.xs
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-f
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/
http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.x
<ws:consumer-config name="Web_Service_Consumer" wsdlLocation="http://tshirt-service.cloudhub.io/

https://docs.mulesoft.com/mule-runtime/3.9/web-service-consumer 24/27
5/3/2020 Web Service Consumer | MuleSoft Documentation

<http:listener-config name="HTTP_Listener_Configuration" host="localhost" port="8081" doc:name

<flow name="orderTshirt" >


<http:listener config-ref="HTTP_Listener_Configuration" path="orders" doc:name="HTTP">
<http:response-builder statusCode="200"/>
</http:listener>
<set-variable variableName="apiKey" value="#['abc12345']" doc:name="Set API Key"/>
<dw:transform-message doc:name="Transform Message">
<dw:input-variable doc:sample="string.dwl" variableName="apiKey"/>
<dw:set-payload><![CDATA[%dw 1.0
%output application/xml
%namespace ns0 http://mulesoft.org/tshirt-service
---
{
ns0#OrderTshirt: {
size: payload.size,
email: payload.email,
name: payload.name,
address1: payload.address1,
address2: payload.address2,
city: payload.city,
stateOrProvince: payload.state,
postalCode: payload.postal,
country: payload.country
}
}]]></dw:set-payload>
<dw:set-property propertyName="soap.header"><![CDATA[%dw 1.0
%output application/java
---
flowVars.apiKey]]></dw:set-property>
</dw:transform-message>
<ws:consumer config-ref="Web_Service_Consumer" operation="OrderTshirt" doc:name="Order T
<dw:transform-message doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/json
---
payload]]></dw:set-payload>
</dw:transform-message>
</flow>

<flow name="listInventory" >


<http:listener config-ref="HTTP_Listener_Configuration" path="inventory" doc:name="HTTP"
<http:response-builder statusCode="200"/>
</http:listener>
<ws:consumer config-ref="Web_Service_Consumer" operation="ListInventory" doc:name="List
<dw:transform-message doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/java
https://docs.mulesoft.com/mule-runtime/3.9/web-service-consumer 25/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.

Learn how to publish a REST API in Mule using APIkit.

Was this article helpful?

👍 Yes, thanks! 👎 No, not really.

Edit on GitHub

Related resources Recommended for you


The value of APIs for business Connectivity benchmark report
What is REST API design? The application network
API development best practices How to design and manage APIs
Watch now on demand
Best practices for microservices
API security best practices
Anypoint Platform overview

Sign up for our newsletter

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.

©2020 MuleSoft LLC, a Salesforce company English Full site

https://docs.mulesoft.com/mule-runtime/3.9/web-service-consumer 27/27

You might also like