Showing posts with label MS Workflow. Show all posts
Showing posts with label MS Workflow. Show all posts

Wednesday, 20 June 2012

MS Workflow behavior extensions do not execute

MS Workflow behavior extensions do not execute

I just came across behaviour problem where I wanted to use custom behaviour, but the behaviour did not execute. I have added behaviour extension as below:

To add behaviour you need to specify your behaviour:

        <behaviorExtensions>
          <add name="dummyLogging" type="dummy.Logging, dummy"/>
        </behaviorExtensions>


Where:
name: name how its refered to.
type:- "object name" + "," +   name of the namespace"

my web.config

<?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0"/>   
  </system.web>  
  <system.serviceModel>
      <extensions>
        <behaviorExtensions>
          <add name="dummyLogging" type="dummy.Logging, dummy"/>
        </behaviorExtensions>
      </extensions>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>


Solution:


Now what I was missing was, say to MS Workflow to execute the custom behaviour. In behaviour we need to activate the behaviour, otherwise it does not get triggered.

<?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0"/>   
  </system.web>  
  <system.serviceModel>
      <extensions>
        <behaviorExtensions>
          <add name="dummyLogging" type="dummy.Logging, dummy"/>
        </behaviorExtensions>
      </extensions>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="true"/>
          <dummyLogging />         
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>

Tuesday, 19 June 2012

Adding service behaviour into MS Workflow

Basically you use an IServiceBehavior to add the extension and a BehaviorExtensionElement to add the IServiceBehavior.


public class StringWriterBehavior : IServiceBehavior
{
    public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
    {
        var host = (WorkflowServiceHost)serviceHostBase;
        host.WorkflowExtensions.Add<TextWriter>(() => new StringWriter());
    }
}

public class StringWriterElement : BehaviorExtensionElement
{
    public override Type BehaviorType
    {
        get { return typeof(StringWriterBehavior); }
    }

    protected override object CreateBehavior()
    {
        return new StringWriterBehavior();
    }
}
And the config file:

<system.serviceModel>
  <extensions>
    <behaviorExtensions>
      <add name=“stringWriter“
           type="OrderService.StringWriterElement, MyWorkflowService"/>
    </behaviorExtensions>
  </extensions>
  <services>
    <service name="OrderWorkflow“
             behaviorConfiguration="OrderWorkflowBehavior">
    </service>
  </services>
  <behaviors>
    <serviceBehaviors>
      <behavior name="OrderWorkflowBehavior">
        <serviceMetadata httpGetEnabled="True"/>
        <stringWriter />
      </behavior>
    </serviceBehaviors>
  </behaviors>
</system.serviceModel>



source:
http://social.msdn.microsoft.com/Forums/en-US/wfprerelease/thread/a9b45eaf-c8e2-444c-819d-e448868e68bb/