Code Samples from todays webcast

by mmilner 26. June 2008 18:01

For those of you who attended my webcast today on workflow communications, the demo code is attached to this post. It includes the base activities used for communication activities (more on these in a later post) and it provides simple example of local communications and web services. The two-way communication activity and sample is also included. 

If you are interested in the webcast check here in the next day to two for the OnDemand link.

 

Enjoy!

 

 

 

Tags:

General Musings | Windows Workflow Foundation

PowerShell for BizTalk Server

by mmilner 26. June 2008 17:29

During my preparation for my Tech Ed talk on BizTalk Server port binding options, I wanted to write a PowerShell script to help me manage the transitions from one demo to another.  For the most part, I was looking for a way to quickly enable / disable receive locations and start / unenlist send ports and orchestrations.  All of this is available in WMI, but I wanted to make some reusable functions in PowerShell so I didn't have to drop into WMI each time I wanted to do it.  I wanted a simple function I could call like so:

EnableReceiveLocation("MYRL")

 

It turns out that creating these functions in a script file is relatively easy.  One issue I ran into, however, is that transitions for send ports and orchestrations are not as straight forward as they are in the UI.  In the UI if a port is unenlisted, I can simply start it.  Under the covers, however, the admin tool is actually enlisting and then starting.  So, in code, I have to call the operations to both enlist and start.  Or, if the port is already enlisted, but not started, then in a function called StartSendPort, I have to just start it.  So there is some checking of the current status rather than just blindly wrapping WMI calls.  You'll need to check the docs in some situations to get the enum values.  I used the hard coded values in my case. 

 

function StartSendPort{
    param([string]$portName)

    $sp = Get-WmiObject MSBTS_SendPort -n root\MicrosoftBizTalkServer -filter "Name='$portName'"

    if($sp -ne $null)
    {
        if($sp.Status -eq 1 -or $sp.Status -eq 2)
        {
            if($sp.Status -eq 1)
            {
                $null = $sp.Enlist()
            }
            $null = $sp.Start()
            Write-Host "Started send port: " + $portName -fore Green
        }
        else
        {
            Write-Host "Send port " + $portName + " is already started." -fore Yellow
        }
    }
    else
    {
        Write-Host "Send port not found" -fore Red
    }
}

 

Where things got a little more challenging was when I wanted to start working with applications.  Applications provide a nice way to manage a group of ports by allowing start/stop functionality; unfortunately, the application is not surfaced through WMI.  Never fear however, b/c PowerShell is built on top of .NET.  All I needed to do was create an instance of the BtsCatalogExplorer class and then I was on my way to managing the applications.  But first, I had to load the assembly that included that class.  I chose to do that using the path, but strong names works very well too.  Then I used the New-Object cmdlet to create an instance and navigate to the application. 

 

[System.Reflection.Assembly]::LoadFrom("C:\Program Files\Microsoft BizTalk Server 2006\Developer Tools\Microsoft.BizTalk.ExplorerOM.dll")

function StopBTSApplication
{
    param([string]$appName)

    $exp = New-Object Microsoft.BizTalk.ExplorerOM.BtsCatalogExplorer
    $exp.ConnectionString = Get-BTSConnectionString
    $app = $exp.Applications[$appName]
    if($app -eq $null)
    {
        Write-Host "Application " $appName " not found" -fore Red
    }
    else
    {
        if($app.Status -ne 2)
        {
            #full stop of application
            $null = $app.Stop(63)
            $null = $exp.SaveChanges()
            Write-Host "Stopped application: " $appName
        }
    }

}

 

And, because I was trying not to hard code too much, I create the connection string using WMI to get the group settings. 

function Get-BTSConnectionString
{
    $group = Get-WmiObject MSBTS_GroupSetting -n root\MicrosoftBizTalkServer
    $dbName = $group.MgmtDBName
    $server = $group.MgmtDBServerName
    [System.String]::Concat("server=", $server, ";database=", $dbName, ";Integrated Security=SSPI")
}

 

Notice that I simply execute the Concat to get the connection string, and because this results in a new string, that value is returned to the pipeline and available to be set in a variable or used in a cmdlet. 

I'm loving the stuff I can do with PowerShell and feel like I'm just scratching the surface.  Hope this helps someone else get a jumpstart as well.  I've attached the PowerShell file with my functions included. 

Attachment: BizTalk_PowerShell.ps1.txt

Tags:

BizTalk Server

Upcoming talks and webcast

by mmilner 9. June 2008 08:28

I've got a couple of fun talks coming up this month.  First, I'm going to be doing an MSDN webcast on Windows Workflow Foundation - Communication in Depth.  I'm going to dive into the core communication architecture, discuss how some of the OOB activities use it, and how you can build your own activities to take advantage of it.  We'll cover one way communication between the host and the workflow, but we'll also look at how to do two-way communication to get a response back from the workflow. 

The talk information can be found at this link:

Windows Workflow Communication in Depth

This talk is also part of a series where you can find other talks from my friends Jon Flanders and Jesus Rodriguez on other .NET 3.5 topics.  The link for the series is here:

http://www.microsoft.com/events/series/msdnnetframework35.aspx?tab=webcasts&id=liveall

 

I'm also doing a local talk this month at the Microsoft office if you are in the Minneapolis area.  I'll be talking about building connected systems with WF and WCF for developers and architects.  This will be a good talk if you are interested in these technologies and want to learn more about how to use them to build real applications. 

Event information and registration

I had a great time at Tech Ed and I'm looking forward to the conferences coming up this fall (Minnesota Developers Conference where I'll be doing talks on LINQ and ADO.NET Data Services and Heartland Developers Conference where I'll be talking about BizTalk Services and the "Internet Service Bus"). 

Tags:

General Musings | Windows Workflow Foundation | Windows Communication Foundation

My Tech Ed Demos

by mmilner 6. June 2008 20:29

Thanks to everyone who came to my session on port binding options in BizTalk Server yesterday.  You can find the demos here including the visual studio solution, binding files for BizTalk and the PowerShell script I used for setting up and running my demos. 

Tags:

BizTalk Server | General Musings