从托管服务器连接到WCF服务时出错

时间:2012-02-21 06:22:58

标签: c# wcf authentication ntlm

这可能是愚蠢的/不可能的。但是,我想要实现的目标如下:

  • 我在Windows Server 2008上的IIS 7中有一个托管WCF Web服务的VM
  • 我正在使用basichttp绑定
  • 客户端代码在其他计算机上运行完美
  • 此服务器VM还需要执行批处理,因此我需要使用客户端访问这些WCF服务
  • 在托管WCF服务的实际邮箱上运行时,我得到了......

    System.ServiceModel.Security.MessageSecurityException:HTTP请求未经授权,客户端身份验证方案为“Ntlm”。从服务器收到的身份验证标头是“Negotiate,NTLM”。 ---> System.Net.WebException:远程服务器返回错误:(401)未经授权。    在System.Net.HttpWebRequest.GetResponse()    at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)    ---内部异常堆栈跟踪结束---

    服务器堆栈跟踪:    在System.ServiceModel.Channels.HttpChannelUtilities.ValidateAuthentication(HttpWebRequest请求,HttpWebResponse响应,WebException responseException,HttpChannelFactory工厂)    在System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest请求,HttpWebResponse响应,HttpChannelFactory工厂,WebException responseException)    at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)    在System.ServiceModel.Channels.RequestChannel.Request(消息消息,TimeSpan超时)    在System.ServiceModel.Dispatcher.RequestChannelBinder.Request(消息消息,TimeSpan超时)    在System.ServiceModel.Channels.ServiceChannel.Call(String action,Boolean oneway,ProxyOperationRuntime operation,Object [] ins,Object [] outs,TimeSpan timeout)    在System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall,ProxyOperationRuntime操作)    在System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

    在[0]处重新抛出异常:    在System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg,IMessage retMsg)    在System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData,Int32 type)

我想知道的是我的尝试是否真的可行 - 我认为没有理由不能从托管机器连接到服务,但细节可能会阻止我 - 如果是,那是什么我需要对我的设置进行更改才能实现它吗?

有关的dll设置绑定如下......

    BasicHttpBinding binding = new BasicHttpBinding();

    binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
    binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm;
    binding.TransferMode = TransferMode.Buffered;
    binding.MaxBufferPoolSize = int.MaxValue;
    binding.MaxReceivedMessageSize = int.MaxValue;
    binding.ReaderQuotas.MaxArrayLength = int.MaxValue;
    binding.ReaderQuotas.MaxStringContentLength = int.MaxValue;
    binding.OpenTimeout = openTimeout;
    binding.SendTimeout = sendTimeout;
    binding.ReceiveTimeout = receiveTimeout;
    binding.CloseTimeout = closeTimeout;

    return binding;

cscript身份验证的输出是......

NTAuthenticationProviders       : (STRING) "Negotiate,NTLM"

该服务设置为要求连接用户所属的网络组的成员资格(PrincipalPermission)。

如下面的评论中所示,我查看了安全事件日志,发现当用户(网络帐户)作为客户端连接到主机上的WCF服务时,有一个条目抱怨该帐户无法登录 - 传递空SID。

An account failed to log on.

Subject:
    Security ID:        NULL SID
    Account Name:       -
    Account Domain:     -
    Logon ID:       0x0

Logon Type:         3

Account For Which Logon Failed:
    Security ID:        NULL SID
    Account Name:       *<network account>*
    Account Domain:     *<account domain>*

Failure Information:
    Failure Reason:     An Error occured during Logon.
    Status:         0xc000006d
    Sub Status:     0x0

问题是,为什么会发生这种情况?

1 个答案:

答案 0 :(得分:1)

post上的方法1可以解决问题......

DisableStrictNameChecking = 1 BackConnectionHostNames =在我的情况下,服务器的完整域名限定别名