从WCF服务的宿主服务器连接到WCF服务时出错

本文关键字:WCF 服务 出错 连接 宿主 服务器 | 更新日期: 2023-09-27 18:25:12

这可能很愚蠢/不可能。然而,我正在努力实现以下目标:

  • 我有一个在Windows Server 2008上的IIS 7中托管WCF web服务的VM
  • 我正在使用basichttp绑定
  • 客户端代码可以在其他机器上完美运行
  • 这个服务器VM还需要执行批处理,所以我需要使用客户端访问它上的这些WCF服务
  • 当在托管WCF服务的实际盒子上运行时,我得到。。。

    System.ServiceModel.Security.MessageSecurityException:HTTP请求未经授权,客户端身份验证方案为"Ntlm"。从服务器收到的身份验证标头为"协商,NTLM"。--->System.Net.WebException:远程服务器返回错误:(401)未经授权。位于System.Net.HttpWebRequest.GetResponse()位于System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChanelRequest.WWaitForReply(TimeSpan超时)---内部异常堆栈跟踪结束---

    服务器堆栈跟踪:位于System.ServiceModel.Channels.HttpChannelUtilities.ValideAuthentication(HttpWebRequest请求、HttpWebResponse响应、WebException响应异常、HttpChannelFactory工厂)位于System.ServiceModel.Channels.HttpChannelUtilities.ValideRequestReplyResponse(HttpWebRequest请求、HttpWebResponse响应、HttpChannelFactory工厂、WebException响应异常)位于System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChanelRequest.WWaitForReply(TimeSpan超时)在System.ServiceModel.Channels.RequestChannel.Request(消息消息,TimeSpan超时)位于System.ServiceModel.Dispatcher.RequestChannelBinder.Request(消息消息,TimeSpan超时)在System.ServiceModel.Channels.ServiceChannel.Call(字符串操作,布尔单向,ProxyOperationRuntime操作,对象[]in,对象[]out,TimeSpan超时)位于System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall,ProxyOperationRuntime操作)在System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage消息)

    在[0]处重新引发异常:在System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage-reqMsg,IMessage-retMsg)在System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&msgData,Int32类型)

我想知道的是,我所尝试的是否真的可能——我看不出有什么理由不能从主机连接到服务,但具体情况可能会阻止我——如果是这样,我需要对我的设置进行哪些更改才能实现?

相关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服务时,有一个条目抱怨帐户登录失败-传递了一个Null 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

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

从WCF服务的宿主服务器连接到WCF服务时出错

这篇文章中的方法1做到了。。。

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