记录凭据传递给WCF Web服务

时间:2012-05-04 17:59:36

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

我有一个配置了传输安全性和Basic 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>

1 个答案:

答案 0 :(得分:0)

检查一下:

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

我相信你可以在IAuthorizationPolicy

中做到这一点