In this exercise we will create a webservice
- The Futurama Editor must be installed.
- Completing the tutorial Creating a Webservice Application first, is recommended.
In this exercise you have to create a webservice that can add two numbers.
Create a webservice that can add two numbers. In SoapUI, verify that you get the correct result for different input.
Take the following steps to do so:
- Open a Notepad and save the data below as an Xml file in the application folder. This file will serve as a test input file to implement the correct behaviour for our webservice. With this input file, the format of the input is also defined.
- Open the Futurama Editor and open a new document. Save the document in the same folder as the Xml file.
- Create a WebService object.
We have to fill in the properties TestValue and XmlOutput.
First we will create the TestValue input.
- Create a Formula Type String 'Path', with the fuction GetPathToDateFiles().
- Create another Formula Type String 'ReadFile', with the function 'ReadFile'. In the Filename you choose for the Formula Concatenate and in the Formula Concatenate you fill in the name of the input xml file (as example Input.xml) and you refer to the Formula Path.
- In the Webservice, refer to the ReadFile formula for the property TestValue. Validate in the Results Window that the Input of your test file is visible here.
- Now we will create the calculation of the result for the webservice.
- Create an XmlNode 'Input'. Go the properties and fill in the URI (http://www.futurama.eu/WebserviceAdd) in the NameSpaces property and choose a prefix, for instance 'a'. In the property Source refer to the formula ReadFile and in the property XPath type in your prefix followed by the element data. (So in our example 'a:data'). Verify that the XmlNode displays your test input in the Results Window.
- Create two XmlFields (type Long) within the XmlNode that retrieve both values of the test input ('a:Add1' and 'a:Add2').
- Create a Formula that adds both numbers in the XmlFields.
- Create an XmlBuilder 'Results' and within the XmlBuilder refer to the Add Formula.
- In the Webservice object, refer to the XmlBuilder in the XmlOutput property. Now we have created the result that the webservice has to give back.
- To define the name of the webservice, create an InterfacesNode and within it a reference to the Webservice object. The name you choose for this reference is the name you have to use when calling the webservice.
- Open SoapUi and verify your application.
- You should add a namespace to your Results XmlBuilder as well. See the download for our solution.
- The Document does not have a StartWebpage (nor other pages), as this is no website application.
You can download our solution for this assignment by clicking the image at the right. (Futurama 184.108.40.206)
Please note that you can very well have a different solution that is just as good as ours.
- (Easy:) Adjust the webservice so that it gives the product instead of the sum of the two input variables.
- (Medium:) Adjust the webservice so that it gives both the product and the sum as output.
- (Medium:) Adjust the webservice so that it returns the input variables in the output as well.