Zulfiqar's weblog

Architecture, security & random .Net

Custom ServiceHostFactory for a XAMLX based Service

Posted by zamd on April 23, 2010


For IIS/WAS hosted services backed by a physical .SVC file (WCF 3.0/3.5) you can specify a custom ServiceHostFactory in the .svc file as part of service specification. There is no such declaration for XAMLX files and instead you can use config-based activation feature to achieve the same result.

If my WCF service is deployed as Service1.xamlx and I want to customize the WorkflowServiceHost before it’s opened and used, I can easily do this using following two steps:

  1. Create a custom ServiceHostFactory by sub classing the default one

namespace DeclarativeServiceLibrary1

{

    public class MyServiceHostFactory : WorkflowServiceHostFactory

    {

        protected override WorkflowServiceHost CreateWorkflowServiceHost(Activity activity, Uri[] baseAddresses)

        {

            return base.CreateWorkflowServiceHost(activity, baseAddresses);

        }

        protected override WorkflowServiceHost CreateWorkflowServiceHost(WorkflowService service, Uri[] baseAddresses)

        {

            var host =  base.CreateWorkflowServiceHost(service, baseAddresses);

            // add your customizations here…

            return host;

        }

    }

}

2.  Configure your custom ServiceHostFactory for your XAMLX file

  <system.serviceModel>

  

    <serviceHostingEnvironment multipleSiteBindingsEnabled=true >

      <serviceActivations>

        <add relativeAddress=~/Service1.xamlx

             service=Service1.xamlx

             factory=DeclarativeServiceLibrary1.MyServiceHostFactory/>

      </serviceActivations>

    </serviceHostingEnvironment>

  </system.serviceModel>

Advertisements

6 Responses to “Custom ServiceHostFactory for a XAMLX based Service”

  1. scott_m said

    Great post! Nice to finally find some guidance for WF/WIF integration.

  2. scott_m said

    Your post does a good job showing where to put the WIF hooks for the XAML service. How would you go about putting the corresponding WF client side WIF hooks in?

  3. Srini Datla said

    Nice post.

  4. […] out my earlier post for additional […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: