【问题标题】:WCF REST Consuming errorWCF REST 消费错误
【发布时间】:2011-08-23 09:26:31
【问题描述】:

我在尝试使用网络服务时不断收到以下错误:

HTTP 请求未经客户端身份验证方案“基本”授权。从服务器收到的身份验证标头是“基本领域”。

Web 服务是使用 WCF 编写的 REST。身份验证是基于 https 的基本身份验证。

我们将不胜感激任何修复错误的帮助。

这是我试过的代码:

    WebHttpBinding webBinding = new WebHttpBinding();
    webBinding.Security.Mode = WebHttpSecurityMode.Transport;
    webBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;

    ChannelFactory<ServiceReferences.BTService.FLDT_WholesaleService> factory = new ChannelFactory<ServiceReferences.BTService.FLDT_WholesaleService>(webBinding,
                                                                        new EndpointAddress(
                                                                            "https://wholesale.fluidata.co.uk/FLDT_BT_wholesale/Service.svc"));
    factory.Endpoint.Behaviors.Add(new WebHttpBehavior());
    factory.Credentials.UserName.UserName = "username";
    factory.Credentials.UserName.Password = "password";

    ServiceReferences.BTService.FLDT_WholesaleService proxy = factory.CreateChannel();

    proxy.AvailabilityCheck("123");

【问题讨论】:

  • 您是否在 IIS 上托管 REST 服务?
  • @Codo 是的。我在 IIS 中托管它
  • 谁应该检查用户名和密码? IIS 还是 WFC 服务?
  • IIS。我确实通过浏览器中的端点检查了用户名和密码是否正确。

标签: c# wcf rest


【解决方案1】:

只要您公开 RESTful 服务,您就可以尝试使用 Fiddler - http://www.fiddler2.com/fiddler2/ 和/或普通的 HttpRequest/HttpResponse。你有没有尝试过这样的事情?

【讨论】:

  • 我可以很好地使用 httpwebrequest 和 HttpResponse。我需要使用 ChannelFactory 来使用它,所以我使用的是类而不是 XML。
【解决方案2】:

先生。 Franek 的回答很有用 - 您将在使用 WCF 时使用 Fiddler,期间。我可以补充一点……这里发生的事情是您已将“基本”指定为您作为客户端的身份验证方案。服务器说“我只允许'基本领域'”作为身份验证方案。什么是“境界”?基本上是一个凭证命名空间:

Realm for HTTP basic authentication

这是另一个有用的链接:Authentication in WinHTTP

我找不到承载 Realm 的属性或方法重载...我可能会尝试手动构造 Authenticate-WWW 标头。

会是这样的:

request.Headers.Add("WWW-Authenticate", string.Format("basic realm=\"{0}\", realm));

“realm”将是服务器期望的值,例如,“www.targetsite.com”。

【讨论】:

  • 您能否发布一个如何手动配置 Authenticate-WWW 标头的示例?
猜你喜欢
  • 2011-04-09
  • 2014-01-31
  • 1970-01-01
  • 1970-01-01
  • 2012-12-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-13
相关资源
最近更新 更多