使用sqlWorkflowInstanceStore时,在WF 4.5中检索WindowsIdentity.Name的问题

时间:2013-07-30 09:35:19

标签: workflow-foundation-4 workflow-foundation-4.5

我正在使用微软的WF 4.5并且在很大程度上取得了相当大的成功。我正在将它用于内部网站,因此在我们的域中使用Windows身份验证。然而,我偶然发现了一个错误,我无法解决。

每当我尝试在web.config中启用sqlWorkflowInstanceStore时,Workflow会在尝试将System.ServiceModel.ServiceSecurityContext.Current.WindowsIdentity.Name分配给变量时抛出异常。

Object reference not set to an instance of an object.

    Server stack trace: 
       at System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter)
       at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
       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)
       at IService.SubmitWorkHours(Int32[]& p_workHours)
       at ServiceClient.SubmitWorkHours(Int32[]& p_workHours)

以下是我的web.config(故意屏蔽了密码)

<?xml version="1.0"?>
<configuration>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IService" sendTimeout="00:05:00">
          <security mode="TransportCredentialOnly">
            <transport clientCredentialType="Windows"/>
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <services>
      <service name="Service1" behaviorConfiguration="WindowsAuthenticationBehavior">
        <endpoint address="http://localhost/SimpleTimesheetService/TimesheetApproval.xamlx" binding="basicHttpBinding" 
                  bindingConfiguration="BasicHttpBinding_IService" contract="IService" name="BasicHttpBinding_IService"/>
      </service>
    </services>

    <behaviors>
      <serviceBehaviors>
        <behavior name="WindowsAuthenticationBehavior">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
          <serviceCredentials>
            <windowsAuthentication includeWindowsGroups="true" allowAnonymousLogons="false"/>
          </serviceCredentials>
          <serviceAuthorization principalPermissionMode="UseWindowsGroups" />
          <sqlWorkflowInstanceStore instanceCompletionAction="DeleteAll" instanceEncodingOption="GZip" instanceLockedExceptionAction="NoRetry" connectionString="server=D801903;database=AppFabPersist;PWD=*******;UID=sa;" hostLockRenewalPeriod="00:00:30" runnableInstancesDetectionPeriod="00:00:05" />
        </behavior>
      </serviceBehaviors>
    </behaviors>

  </system.serviceModel>  
  <system.web>
    <authentication mode="Windows" />
    <compilation debug="true"/>
  </system.web>
</configuration>

如果我注释掉sqlWorkflowInstanceStore,那么WindowsIdentity.Name就会恢复正常。

任何想法为什么?

1 个答案:

答案 0 :(得分:0)

在工作流4.0和4.5中,上下文不公开OperationContext,因此不公开ServiceSecurityContext。

如果您有替代解决方案,请告诉我