尝试使用Web服务时,我一直收到以下错误:
HTTP请求未经授权使用客户端身份验证方案“Basic”。从服务器收到的身份验证标头是“Basic Realm”。
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");
答案 0 :(得分:1)
只要您公开RESTful服务,您就可以尝试使用Fiddler - http://www.fiddler2.com/fiddler2/和/或普通的HttpRequest / HttpResponse。你有没有试过这样的东西?
答案 1 :(得分:0)
先生。 Franek的答案很有用 - 你将使用Fiddler与WCF合作,期间。我可以添加一点......这里发生的事情是你已经将“Basic”指定为客户端的身份验证方案。服务器说“我只允许'Basic Realm'”作为认证方案。什么是'境界'?基本上是凭证命名空间:
Realm for HTTP basic authentication
以下是另一个有用的链接:Authentication in WinHTTP
我找不到携带Realm的属性或方法重载...我可能会尝试手动构建 Authenticate-WWW 标头。
那会是这样的:
request.Headers.Add("WWW-Authenticate", string.Format("basic realm=\"{0}\", realm));
“领域”将是服务器期望的价值,例如“www.targetsite.com”。