ASP.NET Logo Back to WebMatrix Home

 
XML Web Services
'Subtract' WebMethod
In this walkthrough, you will create a new WebMethod that returns a simple type; an Integer representing the difference of two numbers.
  1. Open the myFirstWebService.asmx file in Code view.

     
  2. Add code for a WebMethod called Subtract. The function has two input parameters and one output parameter containing the difference of the two input parameters. All parameters are of type Integer:

     

    <WebMethod> Public Function Subtract(a As Integer, b As Integer) As Integer 
        Return a - b
    End Function
    
  3. Save and run the XML Web Service (hit the start button or press F5 to launch it).

     
  4. A dynamically generated page describing your XML Web Service will automatically appear in a new instance of your Web browser.

     
  5. You will see the XML Web service's HTML description file, containing two methods (Add and Subtract). 

    WS Desc File Sub

  6. Click the Subtract link at the top of the HTML description file.   This will bring up a details page about the Subtract web method -- including schema details about the SOAP payload used to invoke it, as well as an HTML form to invoke and test the method.

    Invoke Subtract WebMethod

  7. Enter 8 in the a parameter box.

     
  8. Enter 3 in the b parameter box.

     
  9. Click Invoke

     
  10. The Web service will return an XML response that gives the difference of the two input parameters in a new instance of your Web browser.

    Subtract WebMethod Result

  11. Close the Web browser instance.

Next Step >>