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: SoapUI_First_Cut_Filter.zip
  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 = 'http://www.webservicex.net/'
    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="http://schemas.xmlsoap.org/soap/envelope/" 
                            xmlns:web="http://www.webserviceX.NET/">
       <soapenv:Header/>
       <soapenv:Body>
          <web:ConvertTemp>
             <web:Temperature>?</web:Temperature>
             <web:FromUnit>?</web:FromUnit>
             <web:ToUnit>?</web:ToUnit>
          </web:ConvertTemp>
       </soapenv:Body>
    </soapenv:Envelope>
    ]]
  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()}   
       Out:mapTree(Orig)
    
       -- 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}
    
       P["soapenv:Envelope"]["soapenv:Body"]
        ["web:ConvertTemp"]["web:Temperature"][1]=
            Out.PATIENT_RESULT[1].ORDER_OBSERVATION[1].OBSERVATION[2].OBX[5][1]
    
       P["soapenv:Envelope"]["soapenv:Body"]
        ["web:ConvertTemp"]["web:FromUnit"][1]=TempF
    
       P["soapenv:Envelope"]["soapenv:Body"]
        ["web:ConvertTemp"]["web:ToUnit"][1]=TempC
  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 = net.http.post{url=Url.. 'ConvertTemperature.asmx', 
                               headers={['Content-type']='text/xml', 
                                        SOAPAction=SoapAction.. 'ConvertTemp'}, 
                               body=P:S(),
                               live=true}
    
       -- 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}   
       Out.PATIENT_RESULT[1].ORDER_OBSERVATION[1].OBSERVATION[2].OBX[5][1]=
       X["soap:Envelope"]["soap:Body"].ConvertTempResponse.ConvertTempResult[1]
       Out.PATIENT_RESULT[1].ORDER_OBSERVATION[1].OBSERVATION[2].OBX[6][2]='°C'
    
       -- Finally push our message, containing the converted values, 
       -- to the queue 
       queue.push{data=Out:S()}

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

2 Comments

Leave A Comment?

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