【发布时间】:2014-05-24 22:48:36
【问题描述】:
我创建了一个具有基于角色的身份验证和授权的 WCF 服务。而每个操作的实现就像
[PrincipalPermission(SecurityAction.Demand, Role = RoleConstants.Customer)]
[PrincipalPermission(SecurityAction.Demand, Role = RoleConstants.CustomerStaff)]
public void DoSomething()
{
}
membership provider 和 RoleManager 是 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 开发机器上运行,另一个在 Server 2012 的测试服务器上运行。WCF 服务的两个实例都运行良好。
但是,1 个月后,我发现 Server 2012 上的实例不再工作,并且身份验证失败,并显示以下消息。
更新:
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)
更新:
我观察到以下情况,排除了一些可能的原因。
- 两台机器上的身份验证数据库是相同的,我可以看到 WCF 服务正在执行 SQL 查询以在客户端发出请求后检索成员信息。
- 我对比了两台机器上的 IIS 绑定和设置,以及 web.config,除了一些地址,基本相同。
- 事件查看器未显示有关 WCF 服务的警告。
- WCF 服务实现由这个属性修饰:公共类 ErrorHandlerBehaviorAttribute:属性、IServiceBehavior、IErrorHandler,所有未捕获的异常都将转到此属性,该属性会将错误记录到日志文件中,但是,日志文件没有记录任何这件事。
我已经比较了两个实例中加载的程序集。在 Windows 7 中,系统程序集基本上来自 Windows\Microsoft.NET\assembly\GACXXX\XXX,但在 Server 2012 中,一些程序集来自 Windows\assembly\NativeImages_v4.0.30319_64,以下是位于 NativeImages 中的一些程序集:
System
System.Activities
System.Core
System.Data.DataSetExtensions
System.Drawing
System.Enumerics
System.ServiceModel.Activities
System.WorkflowServices
System.XAML
System.ServiceModel.Web
相比之下,在 Win 7 中,只有 System 来自 NativeImages。我不确定程序集或本机图像的位置是否会改变行为。
服务和客户端是在 .NET Framework 4.5 上使用 VS 2012 开发的。
还有什么可能导致 Server 2012 上的实例失败?
【问题讨论】:
-
你能添加一个web.config吗?当您从浏览器访问服务的 WSDL 时,它是否有效?
-
是的,当然wsdl发布是可以的。并且请求到达了服务,我可以观察到服务正在与 auth 数据库对话,并根据客户的操作请求检索成员信息。
标签: c# wcf authentication iis windows-server-2012