【问题标题】:How do I authenticate a user to consume a web service programmatically?如何验证用户以编程方式使用 Web 服务?
【发布时间】:2010-02-02 01:16:57
【问题描述】:

我在 IIS 服务器上设置了 Web 服务。当我在网络浏览器中导航到该页面时,它会根据需要询问我的用户名和密码。但是我想在 .NET 应用程序 (C#) 中使用该服务。我需要做什么才能以编程方式提供用户名和密码,以便我可以使用该服务?还是有其他方式我应该对用户进行身份验证?

【问题讨论】:

    标签: .net asp.net iis windows-authentication


    【解决方案1】:

    试试这样的:

    YourWebReference webservice = new YourWebReference();
    webservice.Credentials = new System.Net.NetworkCredential("username","password");
    webservice.DoSomething();
    

    【讨论】:

    • 字段是只读的...我使用了 Visual Studio 服务参考向导,所以我可能还缺少更多内容。
    猜你喜欢
    • 1970-01-01
    • 2012-03-21
    • 1970-01-01
    • 1970-01-01
    • 2012-02-06
    • 2011-06-28
    • 2018-10-03
    • 2021-04-14
    • 1970-01-01
    相关资源
    最近更新 更多