共用方式為


WebServiceHelper.TryUrlRedirection 方法

將 Web 服務物件重新導向至 ASP.NET 開發伺服器,而不是指向所提供之 Web 參考中所定義的資源。

命名空間:  Microsoft.VisualStudio.TestTools.UnitTesting
組件:  Microsoft.VisualStudio.QualityTools.UnitTestFramework (在 Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll 中)

語法

'宣告
Public Shared Function TryUrlRedirection ( _
    client As WebClientProtocol, _
    context As TestContext, _
    identifier As String _
) As Boolean
public static bool TryUrlRedirection(
    WebClientProtocol client,
    TestContext context,
    string identifier
)
public:
static bool TryUrlRedirection(
    WebClientProtocol^ client, 
    TestContext^ context, 
    String^ identifier
)
static member TryUrlRedirection : 
        client:WebClientProtocol * 
        context:TestContext * 
        identifier:string -> bool
public static function TryUrlRedirection(
    client : WebClientProtocol, 
    context : TestContext, 
    identifier : String
) : boolean

參數

  • client
    類型:WebClientProtocol

    接受測試之 Web 服務型別的執行個體。

  • identifier
    類型:String

    識別 ASP.NET 程式開發伺服器 (Development Server) 執行個體的唯一字串。 這符合 AspNetDevelopmentServerAttribute 的名稱參數在測試方法中。

傳回值

類型:Boolean
如果發生重新導向則為 true,否則為 false。

備註

當您使用執行 AspNetDevelopmentServerAttribute 上執行測試時, ASP.NET 程式開發伺服器執行個體的開頭。 這可確保 ASP.NET 程式開發伺服器網站會啟動而且您會知道 URL。 執行測試時,您就可以使用 TryUrlRedirection 來重新導向 Web 服務物件,讓它指向已知的伺服器,而非所提供之 Web 參考中定義的資源。 如果重新導向成功,這個方法會傳回 true,否則傳回 false。 例如,如果識別碼不符合現有 ASP.NET 開發伺服器執行個體的名稱,方法會傳回false.

.NET Framework 安全性

請參閱

參考

WebServiceHelper 類別

Microsoft.VisualStudio.TestTools.UnitTesting 命名空間

TestContext

AspNetDevelopmentServerAttribut