Demo from HDC 10

by Matt Milner 14. September 2010 16:02

Last week I had the pleasure of presenting two sessions at the Heartland Developer’s Conference (HDC). I love this show and meeting people from the central region, as well as catching up with colleagues. It’s always a great time and this year was no different.

For those who attended, you can find the samples I used at the links below. Thanks for coming, I hope you enjoyed the show as much as I did.

 

WF 4 from hello world to real world

Choosing service technology

Tags:

Windows Workflow Foundation | Windows Communication Foundation | Presentations

Two helpful updates for Windows Server AppFabric

by Matt Milner 21. June 2010 10:08

From Damir Dobric (http://developers.de/blogs/damir_dobric):

 

Patch to fix an issue where autostart services start in the wrong application pool:

http://support.microsoft.com/kb/983484

This only applies to Windows 7 and Server 2008 R2 as IIS 7.5 is the only supported platform for autostart in a service. 

 

 

Patch to fix issues where the IIS Manager or PowerShell cmdlets fail due to schema issues in IIS configuration files. 

http://support.microsoft.com/kb/980423

 

There are a number of different error messages that result from this core issue.  In addition to this patch, you should already have installed the hotfix described in the following article:

http://support.microsoft.com/kb/970773

Tags:

AppFabric

Interested in web services interoperability with WCF?

by Matt Milner 21. June 2010 05:38

Then go take this survey and let Microsoft feel your pain!  Not sure anyone will get zapped by their chair when you send feedback, but the team is actively looking into how to make the interop story better, so be sure to get your voice heard.  Oh, and it’s a short survey so not a huge time commitment.

http://mymfe.microsoft.com/Feedback.aspx?formID=283

Tags:

Windows Communication Foundation

Custom web faults with System.ServiceModel.Web 3.x

by Matt Milner 14. June 2010 10:04

A former student approached me with a problem related to the Web programming model using WCF in .NET 3.5.  In short, he was using a custom IErrorHandler to create a custom fault message, but the client was always receiving a generic error.  Even more of a problem was that the custom error was an HTML formatted message, despite having set the response format on the service to JSON.  This caused big problems for the AJAX client trying to reason over that response.  I knew that WCF REST Starter Kit and WCF 4 both allowed for custom error messages, so I did some digging to see what might be at the root of the problem.  It turns out that the WebHttpBehavior inserts its own IErrorHandler and it was getting in the way of the custom handler he was adding.  After pointing this out to Dave, he quickly realized he could create a class that derived from the WebHttpBehavior and override the AddServerErrorHandlers to insert his own error handler.  He also created the requisite BehaviorExtensionElement so the new endpoint behavior could be added in the configuration file. 

 

public class JsonWebHttpBehavior : WebHttpBehavior
    {
        protected override void AddServerErrorHandlers(ServiceEndpoint endpoint,
        System.ServiceModel.Dispatcher.EndpointDispatcher endpointDispatcher)
        {
            endpointDispatcher.DispatchRuntime.ChannelDispatcher.ErrorHandlers.Add(
               new JsonErrorHandler(endpointDispatcher.DispatchRuntime.ChannelDispatcher.IncludeExceptionDetailInFaults));
        }
    }

    public class JsonWebHttpElement : BehaviorExtensionElement
    {
        protected override object CreateBehavior()
        {
            return new JsonWebHttpBehavior();
        }

        public override Type BehaviorType
        {
            get { return typeof(JsonWebHttpBehavior); }
        }
    }

 

The job of the custom error handler is to create a custom fault class that provides data back to the calling application.  This solution nicely takes into consideration the IncludeExceptionDetailsInFaults property to correctly send the details only when configured to do so.  In this case, the status code is always set to 500 to trigger the correct error handling in the client library, but you could also modify this to send more specific HTTP status codes depending on the error message caught on the server. 

 

[DataContract]
    public class JsonFault
    {
        [DataMember]
        public string ExceptionType;

        [DataMember]
        public string Message;

        [DataMember]
        public string StackTrace;
    }

    public class JsonErrorHandler : IErrorHandler
    {
        public JsonErrorHandler(bool includeExceptionDetailInFaults)
        {
            this.includeExceptionDetailInFaults = includeExceptionDetailInFaults;
        }

        public bool HandleError(Exception error)
        {
            return false;
        }

        public void ProvideFault(Exception error,
            System.ServiceModel.Channels.MessageVersion version,
            ref System.ServiceModel.Channels.Message fault)
        {
            JsonFault jsonFault;
            if (includeExceptionDetailInFaults)
            {
                jsonFault = new JsonFault
                {
                    ExceptionType = error.GetType().FullName,
                    Message = error.Message,
                    StackTrace = error.StackTrace
                };
            }
            else
            {
                jsonFault = new JsonFault
                {
                    ExceptionType = typeof(System.Exception).FullName,
                    Message =
                        "An error occurred on the server. See server logs for details.",
                    StackTrace = null
                };
            }

            DataContractJsonSerializer serializer =
                new DataContractJsonSerializer(typeof(JsonFault));

            fault = Message.CreateMessage(version, null, jsonFault, serializer);
            fault.Properties.Add(WebBodyFormatMessageProperty.Name,
                new WebBodyFormatMessageProperty(WebContentFormat.Json));
            WebOperationContext.Current.OutgoingResponse.ContentType = "application/json";
            WebOperationContext.Current.OutgoingResponse.StatusCode =
                System.Net.HttpStatusCode.InternalServerError;
        }

        private bool includeExceptionDetailInFaults;
    }

 

 

You could certainly make modifications to only provide faults for certain types of exceptions (which is what .NET 4 does) log information in the HandleError method, etc.  Many thanks to Dave Grundgeiger for the inspiration to look into this and the final solution which he designed and allowed me to share here. 

Tags:

Windows Communication Foundation

Public courses listed for WCF and WF in .NET 4

by Matt Milner 14. May 2010 07:53

In addition to now having WF 4 offered as a private on-site course, we have several upcoming public offerings of our Double Feature course which has been updated to .NET 4.  I’m excited to be teaching the course at the end of July in Boston and to cover the new features in WCF including configuration enhancements and REST improvements.  The bigger change, of course, is the entirely new WF 4 programming model.  In these open enrollment classes, we will be covering the new programming model, activity development and the runtime services such as persistence and tracking.  We’ll also cover the convergence of these two technologies in Workflow Service and the new message correlation capabilities introduced in .NET 4. 

So, if you are interested in an intense week of training in the Boston (July 26) or SoCal (Oct 11) area on these two great frameworks, register or save a seat before the classes fill up!

Tags:

Windows Workflow Foundation | Windows Communication Foundation

Code samples from Twin Cities .NET User Group (May 2010)

by Matt Milner 7. May 2010 09:55

As promised to those who attended the user group last night, here is a link to the demonstration code I used in my talk on WF 4.  There was a great crowd at the event and I appreciate all the great questions during and after the presentation.  If anyone would like a copy of the slides, use the Contact link to the right to send me email and I’ll send them along.  Thanks for attending and congratulations to the first winner in the drawing who took home a 1 year subscription to Pluralsight On Demand!

 

Tags:

Windows Workflow Foundation | Presentations

WF team releases samples of State Machine and ADO.NET activities

by Matt Milner 3. May 2010 06:25

The WF team has released samples and source code for a state machine (with designer) and some ADO.NET activities.  These are not fully supported code, but do provide you with a glimpse of what Microsoft is planning in these areas, and provide you the ability to give feedback on the implementation. I’m interested to check these out as I’ve got my own runtime, but not design-time state machine implementation that I like. It will be fun to see how it compares. 

 

http://wf.codeplex.com/

Tags:

Windows Workflow Foundation

Microsoft Virtual Launch Event

by Matt Milner 3. May 2010 05:27

Microsoft is holding a virtual launch event on May 20th related to many connected systems technologies including AppFabric (on-premise and cloud) and BizTalk Server.  If you are interested in hearing more about these technologies and how Microsoft feels the on-premise solutions align with the cloud, you should check out this event.  Follow the link for details, calendar link, etc.

 

 

Application Infrastructure: Cloud Benefits Delivered

http://www.appinfrastructure.com

Want to bring the benefits of the cloud to your current IT environment? Cloud computing offers a range of benefits, including elastic scale and never-before-seen applications. While you ponder your long-term investment in the cloud, you can harness a number of cloud benefits in your current IT environment now.

Join us on May 20 at 8:30 A.M. Pacific Time to learn how your current IT assets can harness some of the benefits of the cloud on-premises—and can readily connect to new applications and data running in the cloud. As part of the Virtual Launch Event, Gartner vice president and distinguished analyst Yefim Natis will discuss the latest trends and biggest questions facing the Application Infrastructure space. He will also speak about the role Application Infrastructure will play in helping businesses benefit from the cloud.  Plus, you’ll hear some exciting product announcements and a keynote from Abhay Parasnis, GM of Application Server Group at Microsoft.  Parasnis will discuss the latest Microsoft investments in the Application Infrastructure space aimed at delivering on-demand scalability, highly available applications, a new level of connectivity, and more. Save the date!

Tags:

BizTalk Server | General Musings | AppFabric

Upgrading Visual Studio Solutions with PowerShell

by Matt Milner 9. April 2010 07:20

With the impending release of Visual Studio 2010, I find myself with large numbers of solutions that need be upgraded from VS 2008.  The thought of opening them all manually and running the upgrade wizard was daunting.  Then I considered that I would also need to change the target framework of the projects to .NET 4, and in some cases update the references (why the target framework change didn’t fix that I’m not sure).  So I did what any lazy programmer does, I wrote some code to do it for me. 

At first, I just wanted to upgrade all of my solutions, so I used some PowerShell to find all the solutions and invoke devenv.exe passing in the solution and the /upgrade switch.  This gets a little tricky, as passing command line parameters to executables in PowerShell always seems harder to me than it should be.  But I came up with this one line script that handles it nicely.  I get all the solution files, then do a for each.  The trick was to set variables for the parameters and then invoke it all at once with the variables.  I sleep after so that too many solutions aren’t open at once.  You can play with the sleep time for best results, or remove it if you don’t need it. (Note that I have a 64 bit installation of Windows, so the (x86) in the path)

 

gci * -include *.sln -recurse | foreach-object {$switchName= "/upgrade"; $slnPath = $_; & 'C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe' $slnPath $switchName; start-sleep -seconds 10}

 

That got all my solutions upgraded, but the target framework for each was still .NET 2 or .NET 3.5.  So I used a macro from The Visual Studio Blog to retarget all of my applications to .NET Framework 4.  To run the macro, I used a similar approach with PowerShell, but this time using the /command switch and the name of my macro. 

gci * -include *.sln -recurse | foreach-object {$sln = $_; $vs = "c:\program files (x86)\microsoft visual studio 10.0\common7\ide\devenv.exe"; $cmd = "/command"; $cmdparam = "`"Macros.MyMacros.ProjectManagement.SwitchFramework`""; & $vs $sln $cmd $cmdparam }

 

In this case, I had to wrap the command in quotes, so I used the PowerShell escape character (`). The gotcha with this command is that the IDE stays open after executing the macro.  If you have a lot of solutions, you can run out of resources on your system.  So you may want to break this up and only process a small set of solutions at once.

Finally, I found that when I tried to build my solutions, many of them were referencing the 3.0 version of System.ServiceModel and System.Runtime.Serialization.  I used another macro, and the same PowerShell command, to switch the references.  The macro I used is:

 

Sub SwapReferences()
        For Each project As EnvDTE.Project In DTE.Solution.Projects
            If project.Kind = PrjKind.prjKindCSharpProject OrElse project.Kind = PrjKind.prjKindVBProject Then
                Dim vp As VSProject = CType(project.Object, VSProject)
                Dim ref As VSLangProj.Reference = vp.References.Find("System.ServiceModel")
                If (Not ref Is Nothing) Then
                    ref.Remove()
                    vp.References.Add("System.ServiceModel")
                End If
                Dim dcref As VSLangProj.Reference = vp.References.Find("System.Runtime.Serialization")
                If (Not dcref Is Nothing) Then
                    dcref.Remove()
                    vp.References.Add("System.Runtime.Serialization")
                End If
            End If
        Next
    End Sub

 

Pretty simple and targeted, but it got the job done to replace the references I cared about. 

So, with a few macros, and a little PowerShell, I was able to convert over 30 solutions in a few minutes. 

Tags:

General Musings

Windows Server AppFabric hits beta 2

by Matt Milner 1. March 2010 07:26

You can download the bits and get some great samples in the MSDN development center.  AppFabric is the combination of the distributed caching features previously codenamed “Velocity” and the composite application management features previously codenamed “Dublin”.  These extensions to Windows Server continue to make it a great platform for building applications.  I’m excited about the tooling that AppFabric brings to the management of Workflow Services as it makes it much easier to configure, monitor and take action on deployed services.  In addition, AppFabric adds to the rich tracking story in WF by allowing you to store tracking information in a SQL database so you can do historical analysis. 

This build is based on the Release Candidate of .NET Framework 4, so you’ll want to have that installed first before installing AppFabric. 

Tags:

Windows Workflow Foundation | Windows Communication Foundation | AppFabric