WCF Custom Behavior Deployment Package using Wix Toolsets.

This solution shows how to create setup project for the WCF Custom behavior compiled on Visual Studio 2012. This solution is using Wix toolsets to create deployment package.

I was working on integrating BizTalk Server 2010 / 2013 with Service Bus for Windows. I came across very nice post by Paolo Salvatori http://code.msdn.microsoft.com/How-to-integrate-BizTalk-07fada58. I download the code from his post and compile to generate dll’s. I GAC the dll and edit the machine.config file manually. Wow the behavior extensions are available in my Send Port .

Previously, I already worked on to create WCF Custom Behavior in Visual Studio 2010 in one of my previous project, and created deployment package using Set up/Deployment project in Visual Studio 2010 to automate the process to GAC dll and edit machine.config file. Since after the introduction of Visual Studio 2012, the set up/deployment project is removed. This is really pain now because setup/deployment project is very easy to use.

Now I have a task to automate the process to GAC the dll and edit machine.config file to include the custom behaviors using Visual Studio 2013. While going through the web I came across Wix (Windows Installer XML) is a toolset that builds windows installation packages from XML source code. I download the Wix toolset (http://wixtoolset.org) and installed on VM. Now, in Visual Studio 2012, I can create Wix Project and write xml to install dll and edit machine.config file. Following are the few steps to follow using Wix Project.

Installing Dynamic Link Library into GAC

  1.   Create New Project Setup Project from Wix Toolset.

image

2. Open Product.wxs file. This is purely an XML file with the Namespace included.

image

3. You need to insert your xml code in the Component Group as shown above. The XML which I wrote to GAC the dll’s for Service Bus is shown below.

image

  • Component Id = GUID=
  • File Id= Name= KeyPath=”yes” Vital=”yes” Source= Checksum=”yes” Assembly=” ” AssemblyManifest=

4. Move the dll to the set up project folder and compile set up project to generate set up file.

5. Run the set up file and check the GAC_MSIL folder. All the dll shall be included into GAC.

Edit Machine.Config using Wix toolset Project.

The editing to any config file is done using WixUtilExtension component. You can edit any config file, add database connections, Appsettings etc.

1- Reference the WixUtilExtension into your project. You need to browse the component from the Wix install folder in program files.

2- Reference the namespace “http://wixtoolset.org/schemas/v4/wxs/util” into the product.wxs file. I found that the different version have different namespace, so better grab the namespace from the util.xsd file from your install folder. In my case it was “C:\Program Files (x86)\WiX Toolset v4.0\doc”. Util schema comes with XmlConfig, child element, and used to edit the config files.

image

3- Following is the code for editing the machine.config file. You need to create another Component tag followed by File tag as per below.

image

  • The first part of the xml code is to include Action for Install.

image

  • Second and third Part is to add the element and values. There may be many elements and values.

image

  • Fourth part is to include the action for UnInstall.

image

4- Make sure that the ID shall be unique through out your project.

The content of the XML file is below for Paolo’s WCF custom behavior. The complete project including Paolo’s service bus custom behavior is here.


http://wixtoolset.org/schemas/v4/wxs” xmlns:util=”http://wixtoolset.org/schemas/v4/wxs/util”>


<!– –>

<!– –>

Source=’Microsoft.WindowsAzure.CAT.Samples.ServiceBusForWindowsServer.MessageInspector.dll’ Checksum=”yes” Assembly=”.net” AssemblyManifest=”Level0″>

Source=’Microsoft.WindowsAzure.CAT.Samples.ServiceBusForWindowsServer.ListenUri.dll’ Checksum=”yes” Assembly=”.net” AssemblyManifest=”Level1″>

Source=’Microsoft.WindowsAzure.CAT.Samples.ServiceBusForWindowsServer.Security.dll’ Checksum=”yes” Assembly=”.net” AssemblyManifest=”Level2″>

Source=’Microsoft.WindowsAzure.CAT.Samples.ServiceBusForWindowsServer.SessionChannel.dll’ Checksum=”yes” Assembly=”.net” AssemblyManifest=”Level3″>


<util:XmlConfig
Id=”Machine_Config_Xml_Root”
File=”[WindowsFolder]Microsoft.NET\Framework\v4.0.30319\CONFIG\Machine.Config”
Action=”create”
On=”install”
ElementPath=”//configuration/system.serviceModel/extensions/behaviorExtensions”
Name=”add”
Node=”element”
Sequence=”1″>

<util:XmlConfig
Id=”Machine_Config_Xml_2″
File=”[WindowsFolder]Microsoft.NET\Framework\v4.0.30319\CONFIG\Machine.Config”
ElementPath=”Machine_Config_Xml_Root”
Name=”name”
Value=”biztalkListenUri”
Sequence=”2″>

<util:XmlConfig
Id=”Machine_Config_Xml_3″
File=”[WindowsFolder]Microsoft.NET\Framework\v4.0.30319\CONFIG\Machine.Config”
ElementPath=”Machine_Config_Xml_Root”
Name=”type”
Value=”Microsoft.WindowsAzure.CAT.Samples.ServiceBusForWindowsServer.ListenUri.ListenUriBehaviorExtensionElement, Microsoft.WindowsAzure.CAT.Samples.ServiceBusForWindowsServer.ListenUri, Version=1.0.0.0, Culture=neutral, PublicKeyToken=197ec3eb961f773c”
Sequence=”2″>

<util:XmlConfig
Id=”Machine_Config_Xml_Uninstall_1″
File=”[WindowsFolder]Microsoft.NET\Framework\v4.0.30319\CONFIG\Machine.Config”
Action=”delete”
On=”uninstall”
ElementPath=”//configuration/system.serviceModel/extensions/behaviorExtensions”
Node=”element”
VerifyPath=”add[\[]@name=’biztalkListenUri'[\]]”
Sequence=”1″>


<util:XmlConfig
Id=”Machine_Config_Xml_MessageInspector”
File=”[WindowsFolder]Microsoft.NET\Framework\v4.0.30319\CONFIG\Machine.Config”
Action=”create”
On=”install”
ElementPath=”//configuration/system.serviceModel/extensions/behaviorExtensions”
Name=”add”
Node=”element”
Sequence=”1″>

<util:XmlConfig
Id=”Machine_Config_Xml_4″
File=”[WindowsFolder]Microsoft.NET\Framework\v4.0.30319\CONFIG\Machine.Config”
ElementPath=”Machine_Config_Xml_MessageInspector”
Name=”name”
Value=”bizTalkMessageInspector”
Sequence=”4″>

<util:XmlConfig
Id=”Machine_Config_Xml_5″
File=”[WindowsFolder]Microsoft.NET\Framework\v4.0.30319\CONFIG\Machine.Config”
ElementPath=”Machine_Config_Xml_MessageInspector”
Name=”type”
Value=”Microsoft.WindowsAzure.CAT.Samples.ServiceBusForWindowsServer.MessageInspector.ServiceBusMessageInspectorBehaviorExtensionElement, Microsoft.WindowsAzure.CAT.Samples.ServiceBusForWindowsServer.MessageInspector, Version=1.0.0.0, Culture=neutral, PublicKeyToken=197ec3eb961f773c”
Sequence=”4″>

<util:XmlConfig
Id=”Machine_Config_Xml_Uninstall_2″
File=”[WindowsFolder]Microsoft.NET\Framework\v4.0.30319\CONFIG\Machine.Config”
Action=”delete”
On=”uninstall”
ElementPath=”//configuration/system.serviceModel/extensions/behaviorExtensions”
Node=”element”
VerifyPath=”add[\[]@name=’bizTalkMessageInspector'[\]]”
Sequence=”1″>

<util:XmlConfig
Id=”Machine_Config_Xml_SessionChannel”
File=”[WindowsFolder]Microsoft.NET\Framework\v4.0.30319\CONFIG\Machine.Config”
Action=”create”
On=”install”
ElementPath=”//configuration/system.serviceModel/extensions/behaviorExtensions”
Name=”add”
Node=”element”
Sequence=”1″>

<util:XmlConfig
Id=”Machine_Config_Xml_6″
File=”[WindowsFolder]Microsoft.NET\Framework\v4.0.30319\CONFIG\Machine.Config”
ElementPath=”Machine_Config_Xml_SessionChannel”
Name=”name”
Value=”bizTalkSessionChannel”
Sequence=”6″>

<util:XmlConfig
Id=”Machine_Config_Xml_7″
File=”[WindowsFolder]Microsoft.NET\Framework\v4.0.30319\CONFIG\Machine.Config”
ElementPath=”Machine_Config_Xml_SessionChannel”
Name=”type”
Value=”Microsoft.WindowsAzure.CAT.Samples.ServiceBusForWindowsServer.SessionChannel.SessionChannelBehaviorExtensionElement, Microsoft.WindowsAzure.CAT.Samples.ServiceBusForWindowsServer.SessionChannel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=197ec3eb961f773c”
Sequence=”6″>

<util:XmlConfig
Id=”Machine_Config_Xml_Uninstall_3″
File=”[WindowsFolder]Microsoft.NET\Framework\v4.0.30319\CONFIG\Machine.Config”
Action=”delete”
On=”uninstall”
ElementPath=”//configuration/system.serviceModel/extensions/behaviorExtensions”
Node=”element”
VerifyPath=”add[\[]@name=’bizTalkSessionChannel'[\]]”
Sequence=”1″>

<util:XmlConfig
Id=”Machine_Config_Xml_Security”
File=”[WindowsFolder]Microsoft.NET\Framework\v4.0.30319\CONFIG\Machine.Config”
Action=”create”
On=”install”
ElementPath=”//configuration/system.serviceModel/extensions/behaviorExtensions”
Name=”add”
Node=”element”
Sequence=”1″>

<util:XmlConfig
Id=”Machine_Config_Xml_8″
File=”[WindowsFolder]Microsoft.NET\Framework\v4.0.30319\CONFIG\Machine.Config”
ElementPath=”Machine_Config_Xml_Security”
Name=”name”
Value=”bizTalkSecurity”
Sequence=”8″>

<util:XmlConfig
Id=”Machine_Config_Xml_9″
File=”[WindowsFolder]Microsoft.NET\Framework\v4.0.30319\CONFIG\Machine.Config”
ElementPath=”Machine_Config_Xml_Security”
Name=”type”
Value=”Microsoft.WindowsAzure.CAT.Samples.ServiceBusForWindowsServer.Security.TokenProviderBehaviorExtensionElement, Microsoft.WindowsAzure.CAT.Samples.ServiceBusForWindowsServer.Security, Version=1.0.0.0, Culture=neutral, PublicKeyToken=197ec3eb961f773c”
Sequence=”8″>

<util:XmlConfig
Id=”Machine_Config_Xml_Uninstall_4″
File=”[WindowsFolder]Microsoft.NET\Framework\v4.0.30319\CONFIG\Machine.Config”
Action=”delete”
On=”uninstall”
ElementPath=”//configuration/system.serviceModel/extensions/behaviorExtensions”
Node=”element”
VerifyPath=”add[\[]@name=’bizTalkSecurity'[\]]”
Sequence=”1″>

http://www.sharptalktech.com

Regards,

Shadab

Advertisements

4 thoughts on “WCF Custom Behavior Deployment Package using Wix Toolsets.

  1. Pingback: Dynamic WCF-HttpHeaders for WCF WebHttp adapter | shadabanwer

  2. Pingback: Throwing typed WCF faults back to consumers in a BizTalk messaging only application – Part 3 : Publishing the typed fault contract in the WSDL | Adventures inside the Message Box

  3. Pingback: Throwing typed WCF faults back to consumers in a BizTalk messaging only application – Part 4 : Creating a custom error handling service behavior | Adventures inside the Message Box

  4. Pingback: Throwing typed WCF faults back to consumers in a BizTalk messaging only application – Part 5 : Creating an endpoint behavior to copy headers and the SOAP action from the request to the response | Adventures inside the Message Box

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