【问题标题】:Logging credentials passed to a WCF Web Service传递给 WCF Web 服务的日志记录凭据
【发布时间】:2012-05-14 07:03:53
【问题描述】:

我有一个配置了传输安全性和基本 clientCredentialType 的 Web 服务客户端。 该服务正在使用 HTTPS 端点,我很难诊断错误。我试图向存储请求和响应消息以及传递的凭据(至少是用户名)的应用程序添加一个日志。
对于消息,我使用 MessageInspector 添加了自定义行为。
我如何也可以记录凭据? WCF 中是否有任何扩展点可以做到这一点?还有什么建议吗?
谢谢

编辑:我得到的错误是这样的:

[NotSupportedException: This method is not supported by this class.]
System.Net.BasicClient.Lookup(HttpWebRequest httpWebRequest, ICredentials credentials) +2544984
System.Net.AuthenticationManager.Authenticate(String challenge, WebRequest request, ICredentials credentials) +304
System.Net.AuthenticationState.AttemptAuthenticate(HttpWebRequest httpWebRequest, ICredentials authInfo) +7949046
System.Net.HttpWebRequest.CheckResubmitForAuth() +269
System.Net.HttpWebRequest.CheckResubmit(Exception& e) +126
System.Net.HttpWebRequest.DoSubmitRequestProcessing(Exception& exception) +185
System.Net.HttpWebRequest.ProcessResponse() +75
System.Net.HttpWebRequest.SetResponse(CoreResponseData coreResponseData) +562

[WebException: The request was aborted: The request was canceled.]
System.Net.HttpWebRequest.GetResponse() +7865220
System.ServiceModel.Channels.HttpChannelRequest.WaitForReply(TimeSpan timeout) +99

[CommunicationException: An error (The request was aborted: The request was canceled.) occurred while transmitting data over the HTTP channel.]
System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +4729827
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) +1725
...Application code from here on...

这是一个在 DEV 中正常运行但在 QA 中引发此错误的 Web 应用程序。代码相同,用户在两种环境下都有效。

绑定配置为:

<binding name="CommonBinding" maxReceivedMessageSize="10000000" useDefaultWebProxy="true" openTimeout="00:10:00" sendTimeout="00:10:00">
      <security mode="Transport">
        <transport clientCredentialType="Basic" proxyCredentialType="Basic"
          realm="" />
        <message clientCredentialType="UserName" algorithmSuite="Default" />
      </security>
</binding>

【问题讨论】:

  • 你得到什么错误?您使用的是什么用户/通行证身份验证方法?

标签: .net wcf c#-4.0 wcf-client


【解决方案1】:

看看这个:

http://msdn.microsoft.com/en-us/magazine/cc948343.aspx

我相信你可以在 IAuthorizationPolicy 中做到这一点

【讨论】:

  • 据我了解,这是在服务器端。我想在客户端执行此操作,因为 Web 服务不是 WCF,我对它们没有太多控制权。
  • 所以你想在客户端记录用户身份?是 x.509 还是用户通行证?你可以从 clientCredentials 行为中得到它。
  • 是用户/通行证。您是否有示例说明如何为此使用 clientCredentials 行为?我想捕获有效用户并通过发送,而不是配置的(无论如何,它们是在代码中设置的)
  • 如果只是用户/密码,您可以通过实现自定义消息编码器并通过 xpath 从消息中提取它们来摆脱困境。 msdn.microsoft.com/en-us/library/ms751486.aspx 我会说可能有一种更优雅的方式不检查消息,但唯一能确定发送内容的方法是在编码器中
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-11-15
  • 2013-10-06
  • 1970-01-01
  • 1970-01-01
  • 2010-09-13
  • 2013-09-13
  • 1970-01-01
相关资源
最近更新 更多