【问题标题】:Facing issues when I try to add a webservice in visual studio 2010当我尝试在 Visual Studio 2010 中添加 Web 服务时遇到问题
【发布时间】:2013-11-12 02:21:35
【问题描述】:

我需要使用 Web 服务。该网络服务需要用户身份验证。当我尝试添加对 Web 服务的引用时,我收到一条错误消息

HTTP 请求未经客户端身份验证方案授权 '匿名的'。从服务器收到的身份验证标头是 '基本领域="轴"'。远程服务器返回错误:(401) 未经授权。如果在当前解决方案中定义了服务,请尝试 构建解决方案并再次添加服务引用。

有没有办法摆脱这个错误?

【问题讨论】:

    标签: c# vb.net visual-studio-2010 web-services


    【解决方案1】:

    您需要从您的代码中提供Credentials,并从您的app.config 文件中配置clientCredentialType 类型和realm

    按照以下步骤:

    第一步:
    在您的 app.config 文件中添加以下一组标签。

    <security mode="TransportCredentialOnly">
    <transport clientCredentialType="Basic" proxyCredentialType="None"
     realm="AXIS" />
    

    第 2 步:

    在访问 API 之前,您需要从您的代码中提供凭据(用户名和密码)。

    //您的代码中必须已经有以下两行代码。 假设您的 WebServiceCLient 为 ProjectWebServiceClient

    ProjectWebServiceClient client;
    client = new ProjectWebServiceClient();
    

    //在你的源代码中添加以下两行代码:

     client.ClientCredentials.UserName.UserName = "yourusername";
     client.ClientCredentials.UserName.Password = "yourpassword";
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-07-30
      • 1970-01-01
      • 2014-01-29
      • 1970-01-01
      • 2012-06-05
      • 1970-01-01
      • 2012-08-02
      • 1970-01-01
      相关资源
      最近更新 更多