使用Kerberos在WCF上发送异常 - 检索异常详细信息,使用auth请求跳闸

时间:2012-08-07 09:49:44

标签: c# wcf wcf-security kerberos

我已经设置了一个WCF服务,该服务旨在在Kerberos下运行。我遇到的问题是,每当我从服务向客户端抛出异常时,它似乎都会对异常详细信息发出单独请求,并且在时失败。对于相互身份验证的要求未得到满足远程服务器。'

好消息 - 服务不会抛出异常的请求也能正常工作。

我目前的后备是允许NTLM,我想删除。我想了解问题的核心,试图克服'Kerberos总是很难'的心态。

基本网络详情:

  • 根据NetBios + FQDN为服务注册SPN 名称和App Pool的服务帐户。 (回到http 我们无法使用机器SPN
  • 匿名已停用

尝试了异常类型:

  • 重新抛出原始异常(客户端可以访问基本异常 类型)
  • FaultException,(虽然我不需要自定义异常,但它可能适用于此目的)+将以下内容添加到每个Web服务方法中:

    [FaultContract(typeof运算(FaultException异常))]

客户端详细信息

设置ClientCredential :(客户端)

credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
credentials.Windows.AllowNtlm = false; // Set to true to allow it to work;
credentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Delegation;

以前问题的其他修正:

SpnEndpointIdentity 设置,感谢this question

SpnEndpointIdentity spnEndpointIdentity = new SpnEndpointIdentity("");
var address = new EndpointAddress(EndpointName, spnEndpointIdentity)

停止 407代理错误

BasicHttpBinding.UseDefaultWebProxy = false;

客户收到的异常:(缩写堆栈跟踪)

(似乎表明 ProcessGetResponseWebException 调用正在尝试检索异常细节)

System.ServiceModel.CommunicationException was unhandled
  Message=An error (The request was canceled) occurred while transmitting data over the HTTP channel.
  StackTrace:
       at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)
    Exception rethrown at [0]: 
       at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
       at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
       at Project.IMetadataManagement.GetMetadata(String identifier)
  InnerException: System.Net.WebException
       InnerException: System.Net.ProtocolViolationException
            Message=The requirement for mutual authentication was not met by the remote server.

服务器端详细信息

在网络配置中:

includeExceptionDetailInFaults 为真

<behavior name="Project.MetadataBehavior">
  <serviceMetadata httpGetEnabled="true" />
  <serviceDebug includeExceptionDetailInFaults="true" />
</behavior>

绑定:

<bindings>
  <basicHttpBinding>
    <binding name="BasicHttpEndpointBinding">
      <security mode="TransportCredentialOnly">
        <transport clientCredentialType="Windows" />
      </security>
    </binding>
  </basicHttpBinding>
</bindings>

Windows身份验证设置

<system.webServer>
    <security>
      <authentication>
        <windowsAuthentication enabled="true" useKernelMode="true" useAppPoolCredentials="true" >
          <providers>
            <clear />
            <add value="Negotiate" />
            <add value="NTLM" />
          </providers>
          <extendedProtection tokenChecking="None" />
        </windowsAuthentication>
        <anonymousAuthentication enabled="false" />
      </authentication>
    </security>
  </system.webServer>

服务示例

<services>
      <service behaviorConfiguration="Project.MetadataBehavior" name="Project.MetadataManagement">
        <endpoint address="" binding="basicHttpBinding" bindingConfiguration="BasicHttpEndpointBinding" contract="Project.IMetadataManagement">
        </endpoint>
</service>

任何和所有帮助表示赞赏。我已经清空了实际的项目命名空间,所以希望我没有留下任何笨拙的错位。

感谢。

0 个答案:

没有答案