Using SoapUI to help build a simple Web Service

Create the web service

Before creating a web service that is robust and ready for production, let’s build a simple version that implements temperature conversion without any error handling or modularization.

Before You Start

To set up, you need to create a new channel and import the code for this project:

  1. From the Dashboard, create a new channel with the following components:
    • Source = From LLP
    • Destination = To Channel
    • Filter = enabled
  2. Open the Translator from the Filter component and import this project code:
  3. Commit your first milestone.

How It Works

This section walks through the code you just imported to help you understand how it works:

  1. This code creates the global variables related to the temperature convert web service that will be used throughout our channel:
    local Url = ''
    local SoapAction = 'http://www.webserviceX.NET/'
    local TempF = 'degreeFahrenheit'
    local TempC = 'degreeCelsius'
  2. Next, we declare the global variable “D” (containing the XML request we copied from SoapUI).
    -- The soap request that calls the convert temperature web service
    D = [[<soapenv:Envelope xmlns:soapenv="" 
  3. The main() function begins with HL7 v2 logic that handles the inbound HL7 message and a copy that we use for the outbound message. Then we create a variable “P” to represents our parsed XML request, and populate it with the temperature to be converted (this temperature was passed in through our inbound HL7 v2 message). This is followed by the “from” and “to” temperature (fromFahrenheit and fromCelsius).
    function main(Data)
       -- Lets begin by brininging in some sample data
       local Orig = hl7.parse{vmd='HL7_2.5.1.vmd',data=Data}
       local Out = hl7.message{vmd='HL7_2.5.1.vmd',name=Orig:nodeName()}   
       -- Create a variable "P" that points to our parsed soap request and 
       -- populate it with the patient's temperature that will be converted
       -- and conversion type
       local P = xml.parse{data=D}
  4. Next, we call the temperature convert web service using our populated web request “P”. Then we parse the response that contains our temperature in degrees Celsius. After the response has been parsed, we retrieve the converted value and copy it to our outbound message. Finally, we can push it onto our outbound queue:
       -- Call the convert temperature web service 
       -- and save the result to a local variable  
       local R ={url=Url.. 'ConvertTemperature.asmx', 
                                        SOAPAction=SoapAction.. 'ConvertTemp'}, 
       -- Create variable "X" that points to our parsed soap response and 
       -- populate our outbound message with the converted temperature
       -- and units of measure
       X = xml.parse{data=R}   
       -- Finally push our message, containing the converted values, 
       -- to the queue 

Now that you have a better idea how this all functions, let’s create a more robust, production-ready version!


Leave A Comment?

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.