【发布时间】:2012-01-30 17:21:06
【问题描述】:
我正在通过 WCF(w/.NET 4.0)调用 Web 服务,该服务需要通过 HTTPS 进行基本 HTTP 身份验证(使用用户名和密码)。虽然,我认为我已经正确设置了所有内容,但每当我调用服务时都会收到 401 错误。我监视了 HTTP 流量并注意到 WCF 似乎忽略了我告诉它使用带有用户名和密码的授权标头,因为请求中没有发送任何内容。下面是我的配置。有任何想法吗?谢谢!
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicAuthSecured">
<security mode="Transport">
<transport clientCredentialType="Basic" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://REMOVED FOR CONFIDENTIALITY"
binding="basicHttpBinding" bindingConfiguration="BasicAuthSecured"
contract="Five9.WsAdmin" name="WsAdminPort" />
</client>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
这是我的代码:
var five_9_client = new WsAdminClient();
five_9_client.ClientCredentials.UserName.UserName = “REMOVED FOR CONFIDENTIALITY";
five_9_client.ClientCredentials.UserName.Password = "REMOVED FOR CONFIDENTIALITY";
var call_log_response = five_9_client.getCallLogReport(call_log); //Bombing out here
我遇到了这个异常:
{"HTTP 请求未使用客户端身份验证方案'Basic'。从服务器收到的身份验证标头是''。"}
内部异常:
{"远程服务器返回错误:(401) Unauthorized."}
带有堆栈跟踪:
在 System.ServiceModel.Channels.HttpChannelUtilities.ValidateAuthentication(HttpWebRequest 请求,HttpWebResponse 响应,WebException responseException,HttpChannelFactory 工厂) 在 System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest 请求,HttpWebResponse 响应,HttpChannelFactory 工厂,WebException responseException,ChannelBinding 通道绑定) 在 System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(时间跨度超时) 在 System.ServiceModel.Channels.RequestChannel.Request(消息消息,TimeSpan 超时) 在 System.ServiceModel.Dispatcher.RequestChannelBinder.Request(消息消息,TimeSpan 超时) 在 System.ServiceModel.Channels.ServiceChannel.Call(字符串操作,布尔单向,ProxyOperationRuntime 操作,Object[] 输入,Object[] 输出,TimeSpan 超时) 在 System.ServiceModel.Channels.ServiceChannel.Call(字符串操作,布尔单向,ProxyOperationRuntime 操作,Object[] 输入,Object[] 输出) 在 System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage 方法调用,ProxyOperationRuntime 操作) 在 System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage 消息)
【问题讨论】:
-
您是否因为需要支持 SOAP 1.1 客户端而使用
basicHttpBinding而不是WSHttpBinding?
标签: wcf https basic-authentication