更新:2007 年 11 月
重定向 Web 服务对象,以便它指向 ASP.NET Development Server 而不是 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
用法
Dim client As WebClientProtocol
Dim context As TestContext
Dim identifier As String
Dim returnValue As Boolean
returnValue = WebServiceHelper.TryUrlRedirection(client, _
    context, identifier)
public static bool TryUrlRedirection(
    WebClientProtocol client,
    TestContext context,
    string identifier
)
public:
static bool TryUrlRedirection(
    WebClientProtocol^ client, 
    TestContext^ context, 
    String^ identifier
)
public static function TryUrlRedirection(
    client : WebClientProtocol, 
    context : TestContext, 
    identifier : String
) : boolean
参数
- client 
 类型:System.Web.Services.Protocols.WebClientProtocol- 所测试的 Web 服务类型的实例。 
- context 
 类型:Microsoft.VisualStudio.TestTools.UnitTesting.TestContext- 此单元测试的 TestContext。 
- identifier 
 类型:System.String- 标识 ASP.NET Development Server 实例的唯一字符串。它与测试方法中 AspNetDevelopmentServerAttribute 的 name 参数匹配。 
返回值
如果发生了重定向,则为 true;否则为 false。
备注
当使用 AspNetDevelopmentServerAttribute 运行测试时,将启动 ASP.NET Development Server 的实例。这样可确保 ASP.NET Development Server 站点启动,而且您知道 URL。然后,您在运行测试时,便可以使用 TryUrlRedirection 重定向 Web 服务对象,使它指向已知的服务器,而不是 Web 引用中定义的服务器。如果重定向成功,此方法将返回 true;否则(例如,如果标识符与现有 ASP.NET Development Server 实例的名称不匹配)将返回 false。
权限
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。