我的Silverlight / WCF应用程序在每种服务方法中使用PrincipalPermission来确保用户经过身份验证。当我将所有内容配置为HTTP时,这很好用,但是一旦我配置了服务端点/绑定以支持HTTPS(SSL),当我调用PrincipalPermission对象的Demand()方法时,我会抛出异常。
编辑:我应该提一下,我正在使用IIS 7.5 Express来托管和调试这个项目。
以下是检查以确保用户已经过身份验证的方法。它是从我的每个服务方法中调用的:
protected void SecurityCheck(string roleName, bool authenticated)
{
System.ServiceModel.Web.WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.OK;
PrincipalPermission p = new PrincipalPermission(null, roleName, authenticated);
try
{
p.Demand();
}
catch (Exception ex)
{
/* wrap the exception so that Silverlight can consume it */
ServiceException fault = new ServiceException()
{
/* Code = 1 will mean "unauthenticated!" */
Code = 1, Message = ex.Message
};
throw new FaultException<ServiceException>(fault); }
}
}
所示的执行是“请求委托人失败。”
以下是我的web.config文件的重要部分:
<behavior name="BinarySSL">
<serviceMetadata httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<dataContractSerializer maxItemsInObjectGraph="6553600"/>
<serviceTimeouts transactionTimeout="00:10:00"/>
</behavior>
<binding name="MyApp.Web.Services.ProjectService.customBinding0"
receiveTimeout="00:10:00" sendTimeout="00:10:00">
<binaryMessageEncoding />
<httpsTransport authenticationScheme="Basic"/>
</binding>
<service name="MyApp.Web.Services.ProjectService" behaviorConfiguration="BinarySSL">
<endpoint address="" binding="customBinding" bindingConfiguration="MyApp.Web.Services.ProjectService.customBinding0"
contract="MyApp.Web.Services.ProjectService" />
</service>
这是ClientConfig:
<binding name="CustomBinding_ProjectService">
<binaryMessageEncoding />
<httpsTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
</binding>
<endpoint address="https://localhost:44300/Services/ProjectService.svc"
binding="customBinding" bindingConfiguration="CustomBinding_ProjectService"
contract="ProjectProxy.ProjectService" name="CustomBinding_ProjectService" />
我希望有人可以在这里指出正确的方向。 同样,在我配置SSL服务之前,此配置工作正常。有什么想法吗?
谢谢,
-Scott
我以为我发现了问题,并回答了我自己的问题 - 但我错了。仍然有同样的问题。