Welcome to Windows Workflow Foundation (WF)
Top Tasks :

WF Community Bloggers

Browse by Tags

All Tags » VB » WCF   (RSS)

  • Red Gate to continue development of .NET Reflector

    .NET Reflector, by Lutz Roeder, must be one of the most useful tools I have when developing .NET code. Usually it is the first thing I install right after Visual Studio not even waiting until I need it because I know I will.

    So the big news is that Red Gate, makers of the Ants profiler and lots of other tools, are taking over from Lutz Roeder and will continue developing .NET Reflector. Interesting move and I hope this means a bright future for the .NET Reflector.

    Read more about this here.

     

    Enjoy!

     

    www.TheProblemSolver.nl
    Wiki.WindowsWorkflowFoundation.eu

  • Visual Studio 2008 Service Pack 1 available

    It is available from the subscriptions download at http://msdn.microsoft.com/en-us/subscriptions/default.aspx

     

    Get it while it is hot Smile

     

    Enjoy!

  • More on using a TransactionScopeActivity within a ReceiveActivity

    In a previous blog post I write about what happens when you place a TransactionScopeActivity within a ReceiveActivity and an exception occurs that is supposed to roll back the transaction. In short the story was very bad and we could come up with only a partial workaround, not a pretty sight.

     

    But there is more to it than just that little horror story. Suppose you do the obvious and place the a TransactionScopeActivity within a ReceiveActivity and no exception occurs. Say like the workflow below, please note that the codeActivity1 only sets the return value and causes no error.

     

    image

     

    Now the transaction is committed and the WCF call returns perfectly normally so everything is good right. Well not quite Sad

    The obvious first point is that the TransactionScopeActivity serves no real purpose. After all if it isn't allowed to fail under any circumstances why bother with it in the first place. Well ok there is the point of doing several updates as a single transaction so other users cannot see a partially committed order but that is about it.

    But that is actually the least of my worries as there is a far bigger issue to worry about and that is called workflow persistence.

    Yes that is right. After all when we are using a TransactionScopeActivity workflow persistence is mandatory. The TransactionScopeActivity is decorated with the PersistOnClose attribute so the state of the workflow will be persisted as soon as the transaction is complete. And normally that is a good thing but in this case it is the cause of the second problem because this is still inside the ReceiveActivity. So basically we are storing the workflow state as it is just before returning an answer to the client. Now if everything is running fine that won't matter because the workflow will continue until it is finished and everyone is happy. But suppose the workflow host terminates before the workflow is finished? In this test I added the DelayActivity, and set UnloadOnIdle to false so it doesn't persist the state, giving me the opportunity to kill the workflow runtime. Now if I restart the runtime It is going to reload the last state of the workflow and continue from there. And guess what it's going to do first? You guessed it: it is going to send the response to the client for a second time. Of course the client is no longer around and that action fails with an InvalidOperationException with message "Workflow unloaded between request & response."

    I guess the message is not entirely correct as it should say "Workflow reloaded between request & response." but it's close enough.

    The bottom line is the workflow terminates unless you specifically allow for this to happen and catch the error.

     

    So basically we have a choice between putting the TransactionScopeActivity inside a ReceiveActivity, not being able to throw an error and having a restore problem, or putting the TransactionScopeActivity around the ReceiveActivity, something that only works with a sequential workflow and an initiating ReceiveActivity as I described in the previous post.

    I guess these options make me pretty unhappy Sad.

     

    Enjoy your workflow transactions!

  • Using a TransactionScopeActivity with a WCF ReceiveActivity

    I got an email from a friend last week asking about using a ReceiveActivity and, while receiving, using a TransactionScopeActivity to transitionally save some data in a database. Seems like a common enough scenario right? Well he was having some problems. If everything worked and the transaction succeeded everything was fine and the answer came back. But if an exception occurred and the transaction was aborted be was receiving a real weird error:

    System.ServiceModel.FaultException`1[System.ServiceModel.ExceptionDetail]: Workflow service unexpectedly unloaded from memory while executing a ReceiveActivity. Make sure that the the workflow does not contain any blocking activities within a ReceiveActivity.  (Fault Detail is equal to An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is:
    System.InvalidOperationException: Workflow service unexpectedly unloaded from memory while executing a ReceiveActivity. Make sure that the the workflow does not contain any blocking activities within a ReceiveActivity.).

    If we where to believe the message there was a blocking call, something there most certainly was not!

    And to make things more confusing, if we removed the TransactionScopeActivity and just let the exception occur it would bubble back to the client just as it was supposed to. So what gives?

    Well a lot of people looked at this and in the end we declared this a pretty bad bug. Mind you our words not those from Microsoft. But we did find a workaround. So lets take a look at a repro and how to fix this. My original test workflow looked like this:

    image

    I receive a WCF request, start a transaction, determine the return value in a code activity, throw an exception and return. Seems reasonable right? Well I thought so but it produces the error claiming there is a blocking statement. While tracking this Marvin actually noticed that the workflow idle event was raised! Excuse me, a workflow is becoming idle to undo a transaction sounds kind of wrong. And of course when a TransactionScopeActivity is used in a regular workflow, ie non WCF call, there is no Idle event.

     

    A partial solution

    So the way to get this to work is create the following workflow:

    image

    So instead of creating a TransactionScopeActivity inside of my ReceiveActivity I am doing it the other way round. Sounds kind of weird right? Well I think so but it does do the right thing as it returns the correct fault information to the client and then undoes any transactional work done.

     

    So why does this workaround work in this case?

    The ReceiveActivity has its CanCreateInstance property set to true so this is the request that actually creates and starts the workflow. This means that the workflow is created and starts executing from the top. Yes that is right, it starts from the top, not from the ReceiveActivity so any activities before that are also executed. I suppose that potentially opens a can of worms but we will leave that be for the moment. In this case the WCF request is received, this starts the workflow, this in turn starts the transaction, the message is received and processed and the transaction either commits or, like in this case, rolls back.

    How about a non creating ReceiveActivity?

    Well I am afraid no luck there as this workaround isn't going to work then. The problem is that we start a transaction before we start waiting for the additional WCF calls and the TransactionScopeActivity has a a TimoutDuration. So in all likelihood the transaction timeout will occur before the message is received and this effectively cancels the ReceiveActivity meaning it cannot receive the message.

     

    I think this is a pretty major problem with the way WF and WCF work together. After all transactions a an essential piece of business applications and not being able to use them inside of a WCF request is a deadly sin.

     

    Enjoy with case Smile

  • CodeCamp 2008

    Afgelopen jaar hebben we het eerste CodeCamp in Nederland georganiseerd en dat was een groot succes. De meeste deelnemers vroegen om meer, sommige zelfs om een CodeCamp per kwartaal of een heel weekend lang. Nou hebben we dat laatste nog niet gedaan maar we zijn wel aan de slag gegaan om een nieuw CodeCamp te organiseren. Als datum hebben we zaterdag 6 september gekozen. Gelukkig waren Microsoft en Class-a behulpzaam en kunnen we, net als vorig jaar, weer in het Microsoft Innovation Center in Barneveld terecht. Een mooie datum en locatie om uitgerust van de vakantie een hoop kennis uit te wisselen.

    Het programma staat nog niet helemaal vast, hou daar de website voor in de gaten, maar je kan er ondermeer de bekende Nederlandse sprekers verwachten. Uiteraard kan je zelf ook nog een sessie voorstellen dus als je een idee hebt voor een leuke sessie laat het dan zo snel mogelijk weten.

     

    Dus zet de datum vast in je agenda en meld je zo snel mogelijk aan op de website www.code-camp.nl.

     

    Het CodeCamp is een gezamenlijk initiatief van de SDN, de stichting DotNed en VB Central.

  • How to Download all of Visual Studio 2008 SP1

     VS2008 SP1 Beta is quite a package. By default the installation downloads the packages as needed and when needed. Now that is just fine if you only need to install a single machine. But when you need to install multiple, possibly virtual, machines like I have to it just wastes a lot of bandwidth and time Sad. Fortunately there is a solution and it can be found here in the blog post by Heath Stewart.

    Enjoy! 

  • Project Mole or visual studio visualizers on steroids

    Visual Studio visualizers are pretty cool and can help you quite a bit when debugging but you need to develop them and that just ads to the workload. So how about having someone else do it? Well Microsoft added a few visualizers to VS2008 and VS2008 but they are pretty much limited to text, html and XML data.

     

    Luckily some people liked the idea of using visualizers and actually decided to take it to the next level with project Mole.

    Its a really great viewer to inspect your data and the "Black Ops" feature that allows you to inspect all private members is awesome.

    One quick tip: If you want to use the Mole with any variable use the "new WeakReference(variable)" in the watch window trick!

     

    Enjoy!

    www.TheProblemSolver.nl
    http://wiki.WindowsWorkflowFoundation.eu

  • On the WF ReceiveActivity and WCF bindings

    The new ReceiveActivity and SendActivity that marry Windows Workflow Foundation (WF) and Windows Communication Foundation (WCF) are really cool Smile. Getting started is easy because a new Sequential Workflow Service Library, found under WCF instead of Workflow in VS2008, uses nice defaults for everything. But sooner or later you need to change these defaults and you need to know what can be done and what can't.

    When you want to use the new ReceiveActivity in a workflow you need to use a compatible WCF binding. The reason for this requirement is that the conversation context, see this blog post, is part of the message and needs to be retrieved and returned. The following code returns a list of all WCF binding and how they are composed:

    Sub Main()

    Dim assemblies As New List(Of Assembly)()

    ' .NET 3.0

    assemblies.Add(GetType(ServiceHost).Assembly)

    ' .NET 3.5

    assemblies.Add(GetType(WorkflowServiceHost).Assembly)

    assemblies.Add(GetType(WebServiceHost).Assembly)

     

    Dim query = From assembly In assemblies _

    From type In assembly.GetTypes() _

    Where type.IsSubclassOf(GetType(Binding)) _

    AndAlso Not type.IsAbstract _

    AndAlso type.IsPublic _

    Order By type.Name _

    Select type

     

    PrintBinding(query.ToList)

     

    Console.ReadLine()

    End Sub

     

    Private Sub PrintBinding(ByVal types As List(Of Type))

    For Each type In types

    Console.WriteLine(type.FullName)

    Try

    Dim binding As Binding = _

    CType(Activator.CreateInstance(type), Binding)

    Dim elements = binding.CreateBindingElements

    For Each element In elements

    Console.WriteLine(vbTab + element.GetType().FullName)

    Next

    Catch ex As Exception

    Console.WriteLine(ex.Message)

    End Try

    Console.WriteLine()

    Next

    End Sub

     

    The classes responsible for inserting and removing these conversation tokens are ContextRequestChannel and ContextReplyChannel and they are instantiated by the ContextBindingElement. So seems we are restricted to using BasicHttpContextBinding, NetTcpContextBinding or WSHttpContextBinding.

    So it seems we cannot use NetMsmqBinding which is a shame because one way reliable messaging is the perfect fit for workflow as far as I am concerned. Well not quite so fast because we still have the CustomBinding where we can configure the stack just the way we want right?

    Yeah we do but there is a problem Sad. It turns out the ContextBinding requires a channel with an IReplyChannel interface and the NetMsmqBinding actually implement an IInputChannel or an IOutputChannel. Which one actually depends if you are the client or the service.

    And thinking about how WF/WCF conversations works this restriction makes sense. After all a ReceiveActivity is called without a context in order to create a new workflow, assuming the CanCreateInstance property equals true, and returns the workflow instanceId in the context as part of the response. This design kind of rules out one-way messages and thereby NetMsmqBinding.

    Now this sucks big time if you ask me Sad. I would much rather have seen that you could specify the instanceId of the workflow to be created, just as you can with the WorkflowRuntime.CreateWorkflow() where a number of the overloads let you specify the workflows instanceId. I suppose it is possible to create a different context binding but that would be quite some work and, I assume, duplicate a lot of code already written my Microsoft. So let's hope they see the light and add MSMQ/ReceiveActivity intergration.

     

    Enjoy!

    www.TheProblemSolver.nl
    http://wiki.WindowsWorkflowFoundation.eu

  • Software Developer Event on March 28th

    Next march 28 we are hosting another SDE event in Ede, the Netherlands. There is an impressive list of speakers and sessions, check it out here. I will be doing a session about the new Workflow Foundation features in the .NET framework 3.5. These new features, also known as Silver, enable workflows to work together with Windows Communication Foundation (WCF) in a real nice and intuitive manner Smile

    And just to get a taste here is a screen cast made during the last SDE held in December. The screen cast is in Dutch and for SDN members only!

    Enjoy

  • Visual Studio 2008 and .NET Framework 3.5 Training Kit

    Looking for more information about VS2008 and .NET 3.5?

    I suspect you might just be as there is a ton of new functionality and with the pace of everything coming out it isn't likely that you know it all Smile

    To help learn the new stuff Microsoft has put a Visual Studio 2008 and .NET Framework 3.5 training kit together with lots of labs and presentations. Just go through the list and check what you would like to know more about.

    You can download the trainings kit from here.

    Enjoy!

     

  • Long running workflows and the ReceiveActivity

    Using a ReceiveActivity is a great way of exposing a workflow via a WCF proxy.

    Get started by creating a new project based upon "Sequential Workflow Service Library". This is found in the WCF projects node instead of the Worflow projects node!

    Create a service interface, mine is nice and simple and add a few ReceiveActivity to the workflow and hoop up the service interface to the activities. No big deal so far and we can test things by just pressing F5 and having the WCF Test Client. Actually you can only call functions that are hooked up to an ReceiveActivity with the CanCreateInstance set to True so the WCF Test Client might not be all that useful here if you use multiple ReceiveActivity that are part of a single workflow or conversation.

    Next step is to create a simple console application as a client with the following code:

    Sub SimpleDemo()

    Dim proxy As New ServiceReference1.DoStuffClient

    Console.WriteLine(proxy.AskQuestion("Is this cool?"))

    proxy.AllDone()

    End Sub

     

    This code works just fine Smile until we decide to split it up and recreate the WCF proxy object for part two like this Sad:

    Private Sub Part1()

    Dim proxy As New ServiceReference1.DoStuffClient

    proxy.GetStarted("Maurice")

    Console.WriteLine(proxy.AskQuestion("To be or not to be?"))

    End Sub

     

    Private Sub Part2()

    Dim proxy As New ServiceReference1.DoStuffClient

    Console.WriteLine(proxy.AskQuestion("Is this cool?"))

    proxy.AllDone()

    End Sub

     

    In this case the second proxy object doesn't work at all and we get a FaultException with the message "There is no context attached to incoming message for the service and the current operation is not marked with "CanCreateInstance = true". In order to communicate with this service check whether the incoming binding supports the context protocol and has a valid context initialized."

    So what gives? Well the WCF service needs to know which workflow the request needs to be routed to and uses the WorkflowInstanceId to do so. When you create a proxu and do the first call this WorkflowInstanceId is automatically added and resent with the next request. So we need to retrieve this WorkflowInstanceId and, when we create the second proxy object, add it again. Doing so turns out to be pretty simple and only takes a few extra lines of code:

    Private _instanceId As String

     

    Private Sub Part1()

    Dim proxy As New ServiceReference1.DoStuffClient

    proxy.GetStarted("Maurice")

    Dim contextManager As IContextManager = _

    proxy.InnerChannel.GetProperty(Of IContextManager)()

    Dim context As Dictionary(Of String, String) = _

    contextManager.GetContext()

    _instanceId = context("instanceId")

    Console.WriteLine(proxy.AskQuestion("To be or not to be?"))

    End Sub

     

    Private Sub Part2()

    Dim proxy As New ServiceReference1.DoStuffClient

    Dim contextManager As IContextManager = _

    proxy.InnerChannel.GetProperty(Of IContextManager)()

    Dim context As New Dictionary(Of String, String)

    context.Add("instanceId", _instanceId)

    contextManager.SetContext(context)

    Console.WriteLine(proxy.AskQuestion("Is this cool?"))

    proxy.AllDone()

    End Sub

     

    Basically what we need to do is retrieve the workflow instanceId from the context that is returned with the first call and save that. Next time we create a new proxy object we need to store the same instanceId in the request context before we actually use it and we are good to go Smile Setting the instaceId is actually done through a ClientContextProtocol object which is returned as an IContextManager inside of the channel properties. Check the bold lines in the previous code sample.

    So why is this so important?

    Well one of the most powerful features of Workflow Foundation is its capability to have long running workflows. Now long running workflows would not be very useful if the client application needs to keep its proxy alive for as long as it need to communicate with the workflow. Guess that would make "long running" a very relative thing. But with this technique all the client has to do is save the workflow instanceId somewhere, perhaps a database table, and it can reconnect to the same workflow at a later point in time.

    Enjoy!

  • Microsoft DevDays day 2

    We are just finished with the last day of the 2007 Microsoft DevDays and looking back it would say it was a was a great success. Lots of people, from what I hear almost 25% more than last year, attended and from what I heard most where more than happy. I attended some more good sessions today and did my Worflow Activity development Chalk&Talk. Not all that many people turned up for the C&T session but we still had some interesting discussions. Marcel also did a Workflow presentation including a quick demo of his impressive WCF activities for Workflow Foundation which you can find here.

    I am already looking forward to next year's DevDays event.

    And yes I did swipe my banner and it's in my office now Smile

     

  • Windows Communication Foundation Activities for Windows Workflow Foundation are released.

    I actually missed the release or the WCF activities for windows workflow a few weeks back but Marcel de Vries did a demo yesterday as part of his presentation at the SDE meeting. And I must say its an impressive piece of work that includes the whole enchilada, from sending and receiving messages all the way to generating the actual WCF class required in your service.

    If you need to do any work with WCF and WF before the Visual Studio Orca’s release I can only recommend that you download this library and give it a good try. Of course with Visual Studio Orcas and the .NET 3.5 framework Microsoft will release support for WCF straight out of the box but for now this is the way to go.

    And for that matter if you are interested in developing WF activities yourself taking a good look at these might prove a good lesson as there are a lot of things, like transactions, state management and persistence, to keep in mind when developing custom activities. Also if you are in the Netherlands and want to learn more about WF Activity development I suggest you come to the Microsoft DevDays in Amsterdam where I will be hosting a Chalk&Talk about the subject and Marcel will be presenting on WF as well.

    You can download the WCF activities for windows workflow from: http://www.codeplex.com/WCFWorkflow

    Enjoy!

     

  • Software Developers Conference 2007

    Talking about conferences we pretty much finalized the session schedule for the SDC this year as well. And the session schedule is even more impressive as last year. We are holding back on publishing it for a bit longer until we have confirmation from all the speakers but stay tuned for more Smile

     

    Hope to see you there as well Wink

     

  • Creating Dutch language installer packages in Visual Studio 2005

     

    If have Dutch language users of your applications and you want to localize the installer packages Visual Studio 2005 produces you might want to check out Willem van den Broek work. He created a complete translation so all you have to do is set the Localization property to Dutch and you are good to go.

    Download the package from www.vbcentral.nl/msi. You can find more details on the same page.

    Enjoy!

     

More Posts Next page »

<September 2008>
SuMoTuWeThFrSa
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

Copyright © 2006 Microsoft Corporation. All Rights Reserved. | Terms of Use | Privacy Statement | Contact Us