locked
ExceptionShielding behavior for Workflow 4 RRS feed

  • Question

  • I am not able to configure ExceptionShielding for Workflow. In WCF it was easy to decorate the service with the [ExceptionShielding(policyname)] attribute. How to bring about the same behavior for workflow services. I tried to add the following to the web.config.

    <system.serviceModel>

       <extensions>

          <behaviorExtensions>

            <add name="exceptionShielding" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF.ExceptionShieldingElement, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

          </behaviorExtensions>

        </extensions>

        <bindings />

        <services />

        <behaviors>

          <serviceBehaviors>

            <behavior name="">

              <serviceMetadata httpGetEnabled="true" />

              <serviceDebug includeExceptionDetailInFaults="true" />

              <workflowInstanceManagement />

              <serviceThrottling maxConcurrentInstances="1" />

              <exceptionShielding exceptionPolicyName="myPolicy" />

            </behavior>

          </serviceBehaviors>

        </behaviors>

        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

      </system.serviceModel> 

    And then also have  the Exception Block.

    <exceptionHandling>

        <exceptionPolicies>

          <add name="myPolicy">

            <exceptionTypes>

              <add name="All Exceptions" type="System.Exception, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"

                postHandlingAction="ThrowNewException">

                <exceptionHandlers>

                  <add type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF.FaultContractExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

                    faultContractType="ProjectRegistry.CustomFault, ProjectRegistry, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"

                    name="Fault Contract Exception Handler">

                    <mappings>

                      <add source="Message" name="ErrMsg" />

                    </mappings>

                  </add>

                  <add name="Logging Exception Handler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

                    logCategory="General" eventId="100" severity="Error" title="Enterprise Library Exception Handling"

                    formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling"

                    priority="0" />

                </exceptionHandlers>

              </add>

            </exceptionTypes>

          </add>

        </exceptionPolicies>

      </exceptionHandling>

     

    The above does not seem to work. In my workflow if any unhandled error appears it just goes to the client to the general (Exception ex) block instead of the FaultException<custom type> block.

    Basically ExceptionShielding does not seem to work.

    Thursday, November 25, 2010 10:35 AM

Answers

  • I don't think we support that in WF4, since WorkFlowServiceHost is a different codebase from the WCF service host, just becasue this works for WCF is no guarantee that it is supported for WF4 here.  
    • Marked as answer by Andrew_Zhu Thursday, December 2, 2010 1:53 AM
    Tuesday, November 30, 2010 10:02 PM

All replies

  • I am not able to configure ExceptionShielding for Workflow. In WCF it was easy to decorate the service with the [ExceptionShielding(policyname)] attribute. How to bring about the same behavior for workflow services. I tried to add the following to the web.config.

    <system.serviceModel>

       <extensions>

          <behaviorExtensions>

            <add name="exceptionShielding" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF.ExceptionShieldingElement, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

          </behaviorExtensions>

        </extensions>

        <bindings />

        <services />

        <behaviors>

          <serviceBehaviors>

            <behavior name="">

              <serviceMetadata httpGetEnabled="true" />

              <serviceDebug includeExceptionDetailInFaults="true" />

              <workflowInstanceManagement />

              <serviceThrottling maxConcurrentInstances="1" />

              <exceptionShielding exceptionPolicyName="myPolicy" />

            </behavior>

          </serviceBehaviors>

        </behaviors>

        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

      </system.serviceModel> 

    And then also have  the Exception Block.

     

    <exceptionHandling>

        <exceptionPolicies>

          <add name="myPolicy">

            <exceptionTypes>

              <add name="All Exceptions" type="System.Exception, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"

                postHandlingAction="ThrowNewException">

                <exceptionHandlers>

                  <add type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF.FaultContractExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

                    faultContractType="ProjectRegistry.CustomFault, ProjectRegistry, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"

                    name="Fault Contract Exception Handler">

                    <mappings>

                      <add source="Message" name="ErrMsg" />

                    </mappings>

                  </add>

                  <add name="Logging Exception Handler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

                    logCategory="General" eventId="100" severity="Error" title="Enterprise Library Exception Handling"

                    formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling"

                    priority="0" />

                </exceptionHandlers>

              </add>

            </exceptionTypes>

          </add>

        </exceptionPolicies>

      </exceptionHandling>

     

    The above does not seem to work. In my workflow if any unhandled error appears it just goes to the client to the general (Exception ex) block instead of the FaultException<custom type> block.

    Basically ExceptionShielding does not seem to work.

     


    I got the same problem! I even tried the following code, but it didn't help either!

      protected override System.ServiceModel.Activities.WorkflowServiceHost CreateWorkflowServiceHost(System.ServiceModel.Activities.WorkflowService service, Uri[] baseAddresses)
        {
          var host = base.CreateWorkflowServiceHost(service, baseAddresses);
    
          host.Opening += new EventHandler(host_Opening);
          host.Opened += new EventHandler(host_Opened);
          return host;
        }
    
        void host_Opened(object sender, EventArgs e)
        {
          WorkflowServiceHost host = sender as WorkflowServiceHost;
    
          if (host == null)
            return;
    
          foreach (ChannelDispatcher item in host.ChannelDispatchers)
          {
            item.ErrorHandlers.Add(new Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF.ExceptionShieldingErrorHandler("Logging Policy"));
          }
        }
    
        void host_Opening(object sender, EventArgs e)
        {
          WorkflowServiceHost host = sender as WorkflowServiceHost;
    
          if (host == null)
            return;
          
          foreach (ChannelDispatcher item in host.ChannelDispatchers)
          {
            item.ErrorHandlers.Add(new Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF.ExceptionShieldingErrorHandler("Logging Policy"));
          }
    
          
        }
      }
    
    Friday, November 26, 2010 12:18 AM
  • I don't think we support that in WF4, since WorkFlowServiceHost is a different codebase from the WCF service host, just becasue this works for WCF is no guarantee that it is supported for WF4 here.  
    • Marked as answer by Andrew_Zhu Thursday, December 2, 2010 1:53 AM
    Tuesday, November 30, 2010 10:02 PM