Arjan van IJzendoorn on March 1, 2012
Web services are the preferred way of integrating a Mendix application with external systems. They can be used to retrieve data, send updates and perform operations. In Mendix, calling a web service is something you do in a microflow using the Call Web Service action. Version 3.2.1 introduced the new ‘Mapping’ option and there are now four ways to build the request body (or header) for a web service. With this tech tip we want to help you make the right choice.
A simple web service like the Celsius to Fahrenheit converter from w3schools takes the Celsius value as a string and returns the Fahrenheit value as a string. The ‘Simple’ choice is adequate in this case. It can handle any number of parameters as long as they are primitive.
If the web service has one or more complex parameters, ‘Simple’ does not cut it anymore. In that case, we recommend using the new ‘Mapping’ option. You build the whole request using a domain-to-XML mapping. The advantage of the ‘Mapping’ option is that it support the ‘choice’ construct of XSD at top-level of the request.
The ‘Advanced’ option, which pulls out the top-level elements as parameters, is still around for old times’ sake. This option does not support ‘choice’ but it is used a lot in existing projects. It may disappear in the future, but if it does we will automatically convert usages to the ‘Mapping’ option.
Finally, the ‘Custom’ option is there for cases where the web service does not adhere to standards or uses arcane constructs. Here you can build the the XML of the request by hand.
We have only talked about requests so far. For handling the response of a web service there are two options. If the result is simple, like in the temperature conversion case, you can immediately store the result in a variable. Otherwise, you map the response to Mendix objects using an XML-to-domain mapping.
Look forward to additional improvements in the web service department this year!
Receive Mendix platform tips, tricks, and other resources straight to your inbox every two weeks.