共用方式為


HOW TO:將資料繫結加入至 Web 服務要求

更新:2007 年 11 月

若要將資料繫結 (Data Binding) 加入至 Web 服務要求,您必須手動變更 SOAP XML。如需詳細資訊,請參閱 HOW TO:建立 Web 服務測試

將資料繫結加入至 Web 服務測試

  1. 開啟包含 Web 服務要求的 Web 測試。

    [Web 測試編輯器] 隨即顯示。

  2. 在您要繫結至資料來源的要求樹狀目錄中找到該 Web 服務。在其下選取 [字串內容] 節點。

  3. 在 [屬性] 視窗中,按一下 [字串內容] 屬性中的省略符號 (...)。

    [編輯 HTTP 內容字串] 視窗隨即出現。

  4. 請使用下列語法,以資料繫結值取代 SOAP 主體中的值:

    {{DataSourceName.TableName.ColumnName}}
    

    例如,如果您有下列的程式碼:

    <?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>
    

    您可將它變更如下:

    <?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>{{DataSourceName.Users.Name}}</userName>
                <password>{{DataSourceName.Users.Password}}</password>
                <orderID>{{DataSourceName.Orders.OrderID}}</orderID>
            </CheckStatus>
        </soap:Body>
    </soap:Envelope>
    
  5. 請按一下 [確定],關閉 [編輯 HTTP 內容字串] 視窗。

  6. 在 [檔案] 功能表上,按一下 [儲存] 儲存 Web 測試。

請參閱

工作

逐步解說:將資料繫結加入至 Web 測試

其他資源

Web 測試中的資料繫結

資料驅動的單元測試概觀