The Axis and CXF transports provide WSDL connectors that can be used for invoking remote web services by obtaining the service WSDL. Mule creates a dynamic proxy for the service and then invokes it.
A WSDL endpoint enables you to easily invoke web services without generating a client. At startup, it reads the WSDL to determine how to invoke the remote web service during runtime. When a message is sent through the WSDL endpoint, it is able to construct a SOAP message using the message payload and its knowledge of the expected payload format from the WSDL.
You must provide the full URL to the WSDL of the service to invoke, and you must supply a
method parameter that tells Mule which operation to invoke on the service:
The WSDL URL is prepended with the
wsdl: prefix. Mule checks your class path to see if there is a WSDL provider that it can use to create a client proxy from the WSDL. Mule supports both Axis and CXF as WSDL providers. If you want to use a specific one, you can specify it on the URL as follows:
In general, you should use the CXF WSDL endpoint. The one limitation of the CXF WSDL provider is that it does not allow you to use non-Java primitives (objects that are not a String, int, double, and so on). Sometimes the Axis WSDL generation will not work (incorrect namespaces are used), so you can experiment with each one to see which works best.
Note that there are no specific transformers to set on WSDL endpoints.
By default, the WSDL provider will look for your WSDL by taking the endpoint address and appending
?wsdl to it. With the CXF transport, you have the option of specifying a location for the WSDL that is different from that specified with the
?wsdl parameter. This may be useful in cases where the WSDL isn’t available the normal way, either because the SOAP engine doesn’t provide it or the provider does not want to expose the WSDL publicly.
In these cases, you can specify the
wsdlLocation property of the CXF endpoint as follows:
1 2 3 4 5 6 <endpoint address="wsdl-cxf:http://localhost:8080/book/services/BookService?method=getBooks"> <properties> <property name="wsdlLocation" value="file:///c:/BookService.wsdl"/> </properties> </endpoint>
In this case, the WSDL CXF endpoint works as it normally does, except that it reads the WSDL from the local drive.
This example demonstrates how to take multiple arguments from the console, invoke a web service, and print the output to the screen. It uses the http://www.webservicex.net/WCF/ServiceDetails.aspx?SID=18[Currency Converter] web service on http://www.webservicex.net/[www.webservicex.net].
This service requires two arguments: the "from" currency code and the "to" currency code. When the CXF dispatcher prepares arguments for the invocation of the service, it expects to find a message payload of
Object – that is, an Object array. In the case of the Currency Converter, this should be an array of two Objects - the "from" currency and the "to" currency.
There are several ways to construct this object array, but the easiest way is to use the custom transformer
, which translates a delimited String into an Object array. In the example below, you simply type in a String in the format of
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 <?xml version="1.0" encoding="UTF-8"?> <mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:stdio="http://www.mulesoft.org/schema/mule/stdio" xsi:schemaLocation=" http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.2/mule.xsd http://www.mulesoft.org/schema/mule/stdio http://www.mulesoft.org/schema/mule/stdio/3.2/mule-stdio.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <stdio:connector name="stdioConnector" promptMessage="Enter from and to currency symbols, separated by a comma:"/> <flow name="inputService"> <stdio:inbound-endpoint system="IN"/> <custom-transformer class="org.mule.transformer.simple.StringToObjectArray"> <spring:property name="delimiter" value=","/> </custom-transformer> <outbound-endpoint address="wsdl-cxf:http://www.webservicex.net/CurrencyConvertor.asmx?WSDL&method=ConversionRate"/> <stdio:outbound-endpoint system="OUT"/> </flow> </mule>
For example, type "EUR,USD" to get the conversion rate for Euros to US Dollars, and you’ll get something like this:
1 2 3 Enter from and to currency symbols, separated by a comma: EUR,USD 1.3606