C# WCF服务在服务器2012上的身份验证失败,但在Win7中是否正常?
我已经创建了一个具有基于角色的身份验证和授权的WCF服务。每个操作的实现如下C# WCF服务在服务器2012上的身份验证失败,但在Win7中是否正常?,c#,wcf,authentication,iis,windows-server-2012,C#,Wcf,Authentication,Iis,Windows Server 2012,我已经创建了一个具有基于角色的身份验证和授权的WCF服务。每个操作的实现如下 [PrincipalPermission(SecurityAction.Demand, Role = RoleConstants.Customer)] [PrincipalPermission(SecurityAction.Demand, Role = RoleConstants.CustomerStaff)] public void DoSomething() { } 会员资格提供者和角色管理器是MySql的提供者
[PrincipalPermission(SecurityAction.Demand, Role = RoleConstants.Customer)]
[PrincipalPermission(SecurityAction.Demand, Role = RoleConstants.CustomerStaff)]
public void DoSomething()
{
}
会员资格提供者和角色管理器是MySql的提供者,而不是GAC中的提供者。SSL证书由IIS 7为https生成
我有一些集成测试,比如
using (var client = new MyProxy("DefaultBinding_ILicensingService"))
{
client.ClientCredentials.UserName.UserName = "AbcShop";
client.ClientCredentials.UserName.Password = "tttttttt";
client.DoSomething();
}
一个实例运行在我的开发机器Win7上,另一个运行在服务器2012的测试服务器上。WCF服务的两个实例都运行良好
但是,1个月后,我发现Server2012上的实例不再工作,身份验证失败,并显示以下消息
更新:
System.ServiceModel.Security.MessageSecurityException : An unsecured or incorrectly secured fault was received from the other party. See the inner FaultException for the fault code and detail.
---- System.ServiceModel.FaultException : An error occurred when verifying security for the message.
Stack Trace:
Server stack trace:
at System.ServiceModel.Channels.SecurityChannelFactory`1.SecurityRequestChannel.ProcessReply(Message reply, SecurityProtocolCorrelationState correlationState, TimeSpan timeout)
at System.ServiceModel.Channels.SecurityChannelFactory`1.SecurityRequestChannel.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
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)
更新:
System.ServiceModel.Security.MessageSecurityException : An unsecured or incorrectly secured fault was received from the other party. See the inner FaultException for the fault code and detail.
---- System.ServiceModel.FaultException : An error occurred when verifying security for the message.
Stack Trace:
Server stack trace:
at System.ServiceModel.Channels.SecurityChannelFactory`1.SecurityRequestChannel.ProcessReply(Message reply, SecurityProtocolCorrelationState correlationState, TimeSpan timeout)
at System.ServiceModel.Channels.SecurityChannelFactory`1.SecurityRequestChannel.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
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)
我观察了以下情况,排除了一些可能的原因
System
System.Activities
System.Core
System.Data.DataSetExtensions
System.Drawing
System.Enumerics
System.ServiceModel.Activities
System.WorkflowServices
System.XAML
System.ServiceModel.Web
相比之下,在Win7中,只有来自NativeImage的系统。我不确定程序集或本机映像的位置是否会改变行为
这些服务和客户端是使用VS 2012在.NET Framework 4.5上开发的
还有什么可能使Server 2012上的实例失败?问题已解决
根本原因:服务器2012中缺少ASP.NET MVC程序集
背景是,我希望WCF服务与将来构建的MVC应用程序共享同一个auth数据库。因此,成员提供程序和身份验证管理器来自MVC,数据库是MySql,因此提供程序来自与MVC耦合的开源第三方组件
我的未捕获异常处理程序和事件查看器无法捕获有关缺少程序集的警告的原因如下:
1.dev-PC由一位热爱GAC的开发人员使用。您知道GAC可能会在开发PC中造成很多问题。来自MVC1、2和3的大量组件都在GAC中。
2.与MVC交互的第三个组件在某些地方有一些糟糕的编程实践,其中包含一些关于缺少程序集的异常
在两台计算机中逐个比较加载的程序集后,我发现服务器2012上的WCF服务实例没有WebMatrix.WebData.dll。在我将程序集复制到虚拟目录的bin目录后,在我逐个复制报告的缺失程序集后,我收到了一系列关于更多缺失程序集的错误消息。这些组件基本上属于MVC。错误消息以HTML格式出现在服务响应的客户端,以及服务器端的事件查看器中
因此,我现在确保部署脚本包含相应的程序集
显然,在服务从auth数据库检索到成员信息后,服务将把这些信息委托给MVC的其他程序集进行进一步处理,而第三个组件不知何故吞下了关于缺少程序集的异常。认证的其他部分得到了错误的信号,然后给出了关于“验证安全性…”的误导性警告信息
教训是:
1.不要在开发人员计算机中使用GAC。如果您从某人那里继承了一台开发机器,那么最好花点时间通过XCopy将一些本应是私有程序集的程序集解压到gac上。
2.一些第三方组件可能有一些针对防御编程的肮脏做法。在我的例子中,组件包含了关于缺少组件的警告。
3.在调查其他可能的原因之前比较加载的程序集更便宜。我使用Process Explorer在w3wp.exe中列出加载的程序集。请添加一个web.config文件好吗?当您从浏览器访问服务的WSDL时,它是否工作?是的,当然WSDL发布是可以的。请求到达了服务,我可以观察到服务正在与auth数据库通信,并在客户端请求操作时检索成员信息。很好的分析+1.