Udostępnij za pośrednictwem


How to: Create a Web Service Test

You can use a Web test to test Web services. By using the Insert Request and Insert Web Service Request options, you can customize the individual requests in the Web Test Editor to locate Web service pages. Typically, you do not display these pages in the Web application. Therefore, you must customize the request to gain access to these pages.

The following procedures use a Web service that is contained within the Commerce Starter Kit. You can download it from ASP.NET Starter Kits.

Note

You can test a Web service that is not hosted on a Web server by using the ASP.NET Development Server. For more information, see Unit Tests for ASP.NET Web Services.

To test a Web service

  1. Create a new Web test. As soon as the browser opens, click Stop.

  2. In the Web Test Editor, right-click the Web test and select Add Web Service Request.

  3. In the Url property of the new request, type the name of the Web service, such as https://localhost/storecsvs/InstantOrder.asmx.

  4. Open a separate session of the browser and type the URL of the .asmx page in the Address toolbar. Select the method that you want to test and examine the SOAP message. It contains a SOAPAction.

  5. In the Web Test Editor, right-click the request and select Add Header to add a new header. In the Name property, type SOAPAction. In the Value property, type the value that you see in SOAPAction, such as "http://tempuri.org/CheckStatus".

  6. In the String Body node, put text/xml in the Content Type property.

  7. Return to the browser in step 4, select the XML portion of the SOAP request from the Web service description page and copy it to the clipboard.

  8. The XML content resembles the following example:

    <?xml version="1.0" encoding="utf-8"?>

    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="https://schemas.xmlsoap.org/soap/envelope/">

        <soap:Body>

            <CheckStatus xmlns="http://tempuri.org/">

                <userName>string</userName>

                <password>string</password>

                <orderID>int</orderID>

            </CheckStatus>

        </soap:Body>

    </soap:Envelope>

  9. Return to the Web Test Editor and then click the ellipsis (…) in the String Body property. Paste the contents of the clipboard into the property.

  10. You must replace any placeholder values in the XML with valid values for the test to pass. In the previous sample you would replace the two instances of string and one int. This Web service operation will only complete if there is a registered user who has placed an order.

  11. Right-click the Web service request and select Add URL QueryString Parameter.

  12. Assign the query string parameter a name and value. In the previous example, the name is op and the value is CheckStatus. This identifies the Web service operation to perform.

    Note

    You can use data binding in the SOAP body to replacing any placeholder value with data bound values by using the {{DataSourceName.TableName.ColumnName}} syntax. For more information, see How to: Add Data Binding to a Web Request.

  13. Run the test. In the top pane of the Web Test Viewer, select the Web service request. In the bottom pane, select the Web Browser tab. The XML that is returned by the Web service, and the results of any operations, will be displayed.

See Also

Tasks

How to: Add Data Binding to a Web Request

How to: Record a Web Test