Author: Richard Seroter

  • MVP Again

    Thanks to the Microsoft team for granting me a third straight BizTalk MVP.  I suspect that they keep doing this just to see what regrettable statements I’ll make at the next MVP Summit.  Either way, it’s an honor to receive, and I’m grateful for the perks it has to offer.

    I need to get ready for the Summit in February by preparing my list of ludicrous product features which I’ll be demanding be added to BizTalk Server 2011 (e.g. use text files for storage instead of the MessageBox, XBox-themed skins for the Mapper, functoids that multiply any number by pi, low latency processing, etc).

    Anyway, thanks to all of you who continue to visit here, buy my book, and put up with my shenanigans.  Always appreciated.

    Share

  • Populating Word 2007 Templates Through Open XML

    I recently had a client at work interested in populating contracts out of the information stored in their task tracking tool.  Today this is a manual process where the user opens up a Microsoft Word template and retypes the data points stored in their primary application.

    I first looked at a few commercial options, and then got some recommendations from Microsoft to look deeper into the Open XML SDK and leverage the native XML formats of the Office 2007 document types.  I found a few articles and blog posts that explained some of the steps, but didn’t seem to find a single source of the whole end to end process.  So, I figured that I’d demonstrate the prototype solution that I built.

    First, we need a Word 2007 document.  Because I’m not feeling particular frisky today, I will fill this document with random text using the ever-useful “=rand(9)” command to make Word put 9 random paragraphs into my document.

    2009.12.23word01

    Next, I switch to the Developer tab to find the Content Controls I want to inject into my document.  Don’t see the Developer tab?  Go here to see how to enable it.

    2009.12.23word02

    Now I’m going to sprinkle a few Text Content Controls throughout my document.  The text of each control should indicate the type of content that goes there.  For each content control on the page, select it and choose the Properties button on the ribbon so that you can provide the control with a friendly name. 

    2009.12.23word03

    At this point, I have four Content Controls in my document and each has a friendly title.  Now we can save and close the document. As you probably know by now, the Office 2007 document formats are really just zip files.  If you change the extension of our just-saved Word doc from .docx to .zip, you can see the fun inside.

    2009.12.23word04

    I looked a few options for manipulating the underlying XML content and finally ended up on the easiest way to update my Content Controls with data from outside.  First, download the Word 2007 Content Control Toolkit from CodePlex.  Then install and launch the application.  After browsing to our Word document, we see our friendly-named Content Controls in the list.

    2009.12.23word05

    You’ll notice that the XPath column is empty.  What we need to do next is define a Custom XML Part for this Word document, and tie the individual XML nodes to each Content Control.  On the right hand side of the Word 2007 Content Control Toolkit you’ll see a window that tells us that there are currently no custom XML parts in the document.

    2009.12.23word06

    The astute among you may now guess that I will click the “Click here to create a new one.”  I have smart readers.  After choosing to create a new part, I switched to the Edit view so that I could easily hand craft an XML data structure.

    2009.12.23word07

    For a more complex structure, I could have also uploaded an existing XML structure.  The values I put inside each XML node are the values that the Word document will display in each content control.  Switch to the Bind view and you should see a tree structure.

    2009.12.23word08

    Click each node, and then drag it to the corresponding Content Control.  When all four are complete, the XPath column in the Content Controls should be populated.

    2009.12.23word09

    Go ahead and save the settings and close the tool.  Now, if we once again peek inside our Word doc by changing it’s extension to .zip,  we’ll see a new folder called CustomXml that has our XML definition in there.

    2009.12.23word10

    For my real prototype I built a WCF service that created the Word documents out of the templates and loaded them into SharePoint.  For this blog post, I’ll resort to a Console application which reads the template and emits the resulting Word document to my Desktop.  You’ll get the general idea though.

    If you haven’t done so already, download and install the Open XML Format SDK 1.0 from Microsoft.  After you’ve done that, create a new VS.NET Console project and add a reference to DocumentFormat.OpenXML.  Mine was found here: C:\Program Files\OpenXMLSDK\1.0.1825\lib\DocumentFormat.OpenXml.dll. I then added the following “using” statements to my console class.

    using DocumentFormat.OpenXml;
    using DocumentFormat.OpenXml.Packaging;
    using System.Xml; using System.IO;
    

    Next I have all the code which makes a copy of my template, loads up the Word document, removes the existing XML part, and adds a new one which has been populated with the values I want within the Content Controls.

    static void Main(string[] args)
            {
    
                Console.WriteLine("Starting up Word template updater ...");
    
                //get path to template and instance output
                string docTemplatePath = @"C:\Users\rseroter\Desktop\ContractSample.docx";
                string docOutputPath = @"C:\Users\rseroter\Desktop\ContractSample_Instance.docx";
    
                //create copy of template so that we don't overwrite it
                File.Copy(docTemplatePath , docOutputPath);
    
                Console.WriteLine("Created copy of template ...");
    
                //stand up object that reads the Word doc package
                using (WordprocessingDocument doc = WordprocessingDocument.Open(docOutputPath, true))
                {
                    //create XML string matching custom XML part
                    string newXml = "<root>" +
                        "<Location>Outer Space</Location>" +
                        "<DocType>Contract</DocType>" +
                        "<MenuOption>Start</MenuOption>" +
                        "<GalleryName>Photos</GalleryName>" +
                        "</root>";
    
                    MainDocumentPart main = doc.MainDocumentPart;
                    main.DeleteParts<CustomXmlPart>(main.CustomXmlParts);
    
                    //add and write new XML part
                    CustomXmlPart customXml = main.AddNewPart<CustomXmlPart>();
                    using (StreamWriter ts = new StreamWriter(customXml.GetStream()))
                    {
    
                        ts.Write(newXml);
                    }
    
                //closing WordprocessingDocument automatically saves the document
                }
    
                Console.WriteLine("Done");
                Console.ReadLine();
            }
    

    When I run the console application, I can see a new file added to my Desktop, and when I open it, I find that my Content Controls now have the values that I set from within my Console application.

    2009.12.23word11

    Not bad.  So, as you can imagine, it’s pretty simple to now take this Console app, and turn it into a service which takes in an object containing the data points we want added to our document.  So while this is hardly a replacement for a rich content management or contract authoring tool, it is a quick and easy way to do a programmatic mail merge and update existing documents.  Heck, you could even call this from a BizTalk application or custom application to generate documents based on message payloads.  Fun stuff.

    Share

  • Building WCF Workflow Services and Hosting in AppFabric

    Yesterday I showed how to deploy the new WCF 4.0 Routing Service within IIS 7.  Today, I’m looking at how to take one of those underlying services we built and consume it from a WCF Workflow Service hosted in AppFabric.

    2009.12.17fwf08

    In the previous post, I created a simple WCF service called “HelloServiceMan” which takes a name and spits back a greeting.  In this post, I will use this service completely illogically and only to prove a point.  Yes, I’m too lazy right now to create a new service which creates a more realistic scenario.  What I DO want is to call into my workflow, immediately send a response back, and then go about calling my existing web service.  I’m doing this to show that if my downstream service was down, my workflow (hosted with AppFabric) can be suspended, and then resume once my downstream service comes back online.  Got it?  Cool.

    First, we need a WCF Workflow Service app.  In VS 2010, I pick this from the “Workflow” section.

    2009.12.17fwf01

    I then added a single class file to this project which holds data contracts for the input and output message of the workflow service.

    [DataContract(Namespace="https://seroter.com/Contracts")]
       public class NewOrderRequest
       {
           [DataMember]
           public string ProductId { get; set; }
           [DataMember]
           public string CustomerName { get; set; }
       }
    
       [DataContract(Namespace = "https://seroter.com/Contracts")]
       public class OrderAckResponse
       {
           [DataMember]
           public string OrderId { get; set; }
       }
    

    Next I added a Service Reference to my existing WCF service.  This is the one that I plan to call from within the workflow service.  Once I have my reference defined, and build my project, a custom Workflow Activity should get added to my Toolbox.

    If you’re familiar with building BizTalk orchestrations, then working with the Windows Workflow design interface is fairly intuitive.  Much like an orchestration, the first thing I do here is define my variables.  This includes the default “correlation handle” object which was already there, and then variables representing the input/output of my workflow service, and the request/response messages of my service reference.

    2009.12.17fwf02

    Notice that for variables which aren’t explicitly instantiated by receiving messages into the workflow (i.e. initial received message, response from service call) have explicit instantiation in the “Default” column.

    Next I sketched out the first part of the workflow which receives the inbound “order request” (defined in the above data contract), sets a tracking number and returns that value to the caller.  Think of when you order a package from an online merchant and they immediately ship you a tracking code while starting their order processing behind the scenes.

    2009.12.17fwf03

    Next I call my referenced service by first setting the input variable attribute value, and then using the custom Workflow Activity shape which encapsulates the service request and response (once again, realize that this content of this solution makes no sense, but the principles do).

    2009.12.17fwf04

    After building the solution successfully, we can get this deployed to IIS 7 and running in the AppFabric.  After creating an IIS web application which points to this solution, we can right click our new application and choose .NET 4 WCF and WF and then Configure.

    2009.12.17fwf05

    On the Workflow Persistence tab, I clicked the Advanced button and made sure that on unhandled errors that I abandon and suspended.

    2009.12.17fwf06

    If you are particularly astute, you may notice at the top of the previous image that there’s an error complaining about the net.pipe protocol missing from my Enabled Protocols.  HOWEVER, there is a bug/feature in this current release where you should ignore this and ONLY add net.pipe to the Enabled Protocols at the root web site.  If you put it down at the application level, you get bad things.

    So, now I can browse to my workflow service and see a valid service endpoint.

    2009.12.17fwf07

    I can call this service from the WCF Test Client, and hopefully I not only get back the immediate response, but also see a successfully completed workflow in the AppFabric console. Note that if you don’t see things showing up in your AppFabric console, check your list of Windows Services and make the sure the Application Server Event Collector is started.

    2009.12.17fwf09

    Now, let’s turn off the WCF service application so that our workflow service can’t complete successfully.  After calling the service again, I should still get an immediate response back from my workflow since the response to the caller happens BEFORE the call to the downstream service.  If I check the AppFabric console now, I see this:

    2009.12.17fwf11

    What the what??  The workflow didn’t suspend, and it’s in a non-recoverable state.  That’s not good for anybody.  What’s missing is that I never injected a persistence point into my workflow, so it doesn’t have a place to pick up and resume.  The quickest way to fix this is to go back to my workflow, and on the response to the initial request, set the PersistBeforeSend flag so that the workflow forces a persistence point.

    2009.12.17fwf12

    After rebuilding the service, and once again shutting down the downstream service, I called my workflow service and got this in my AppFabric console:

    2009.12.17fwf13

    Score!  I now have a suspended instance.  After starting my downstream service back up, I can select my suspended instance and resume it.

    2009.12.17fwf14

    After resuming the instance, it disappears and goes under the “Completed Instances” bucket.

    There you go.  For some reason, I just couldn’t find many examples at all of someone building/hosting/suspending WF 4.0 workflow services.  I know it’s new stuff, but I would have thought there was more out there.  Either way, I learned a few things and now that I’ve done it, it seems simple.  A few days ago, not so much.

  • Hosting the WCF 4.0 Routing Service in IIS 7

    I recently had occasion to explore the new WCF 4.0 Routing Service and thought I’d share how I set up a simple solution that demonstrated its capabilities and highlights how to host it within IIS.

    [UPDATE: I’ve got a simpler way to do this in a later post that you can find here.]

    This new built-in service allows us to put a simple broker in front of our services and route inbound messages based on content, headers, and more.  Problem for me was that every demo I’ve seen of this thing (from PDC, and other places) show simple console hosts for the service and not a more realistic web server host.  This is where I come in.

    First off, I need to construct the services that will be fronted by the Routing Service.  In this simple case, I have two services that implement the same contract.  In essence, these services take a name and gender, and spit back the appropriate “hello.”  The service and data contracts look like this:

    [ServiceContract]
        public interface IHelloService
        {
            [OperationContract]
            string SayHello(Person p);
        }
    
        [DataContract]
        public class Person
        {
            private string name;
            private string gender;
    
            [DataMember]
            public string Name
            {
                get { return name; }
                set { name = value; }
            }
    
            [DataMember]
            public string Gender
            {
                get { return gender; }
                set { gender = value; }
            }
        }
    

    I then have a “HelloServiceMan” service and “HelloServiceWoman” service which implement this contract.

    public class HelloServiceMan : IHelloService
        {
    
            public string SayHello(Person p)
            {
                return "Hey Mr. " + p.Name;
            }
        }
    

    I’ve leveraged the new default binding capabilities in WCF 4.0 and left my web.config file virtually empty.  After deploying these services to IIS 7.0, I can use the WCF Test Client to prove that the service performs as expected.

    2009.12.16router01

    Nice.  So now I can add the Routing Service.  Now, what initially perplexed me is that since the Routing Service is self contained, you don’t really have a *.svc file, but then I didn’t know how to build a web project that could host the service.  Thanks to Stephen Thomas (who got code from the great Christian Weyer) I got things working.

    You need three total components to get this going.  First, I created a new, Empty ASP.NET Web Application project and added a .NET class file.  This class defines a new ServiceHostFactory class that the Routing Service will use.  That class looks like this:

    class CustomServiceHostFactory : ServiceHostFactory
    {
        protected override System.ServiceModel.ServiceHost CreateServiceHost(System.Type serviceType, System.Uri[] baseAddresses)
        {
            var host = base.CreateServiceHost(serviceType, baseAddresses);
    
            var aspnet = host.Description.Behaviors.Find<AspNetCompatibilityRequirementsAttribute>();
    
            if (aspnet == null)
            {
                aspnet = new AspNetCompatibilityRequirementsAttribute();
                host.Description.Behaviors.Add(aspnet);
            }
    
            aspnet.RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed;
    
            return host;
        }
    }
    

    Here comes the tricky, but totally logical part.  How do you get the WCF Routing Service instantiated?  Add a global.asax file to the project and add the following code to the Application_Start method:

    using System.ServiceModel.Activation;
    using System.ServiceModel.Routing;
    using System.Web.Routing;
    
    namespace WebRoutingService
    {
        public class Global : System.Web.HttpApplication
        {
    
            protected void Application_Start(object sender, EventArgs e)
            {
                RouteTable.Routes.Add(
                   new ServiceRoute("router", new CustomServiceHostFactory(),
                       typeof(RoutingService)));
            }
    

    Here we stand up the Routing Service with a “router” URL extension.  Nice.  The final piece is the web.config file.  Here is where you actually define the Routing Service relationships and filters.  Within the system.serviceModel tags, I defined my client endpoints that the router can call.

    <client>
          <endpoint address="http://localhost/FirstWcfService/HelloServiceMan.svc"
              binding="basicHttpBinding" bindingConfiguration="" contract="*"
              name="HelloMan" />
          <endpoint address="http://localhost/FirstWcfService/HelloServiceWoman.svc"
              binding="basicHttpBinding" bindingConfiguration="" contract="*"
              name="HelloWoman" />
        </client>
    

    The Routing Service ASP.NET project does NOT have any references to the actual endpoint services, and you can see here that I ignore the implementation contract.  The router knows as little as possible about the actual endpoints besides the binding and address.

    Next we have the brand new “routing” configuration type which identifies the filters used to route the service messages.

    <routing>
          <namespaceTable>
            <add prefix="custom" namespace="http://schemas.datacontract.org/2004/07/FirstWcfService"/>
          </namespaceTable>
          <filters>
            <filter name="ManFilter" filterType="XPath" filterData="//custom:Gender = 'Male'"/>
            <filter name="WomanFilter" filterType="XPath" filterData="//custom:Gender = 'Female'"/>
          </filters>
          <filterTables>
            <filterTable name="filterTable1">
              <add filterName="ManFilter" endpointName="HelloMan" priority="0"/>
              <add filterName="WomanFilter" endpointName="HelloWoman" priority="0"/>
            </filterTable>
          </filterTables>
        </routing>
    

    I first added a namespace prefix table, then have a filter collection which, in this case, uses XPath against the inbound message to determine the gender value within the request.  Note that if you want to use a comparison operation such as “<” or “>”, you’ll have to escape it in this string to “&gt;” or “&lt;”.  Finally, I have a filter table which maps a particular filter to which endpoint should be applied.

    Finally, I have the service definition and behavior definition.  These both leverage objects and configuration items new to WCF 4.0.  Notice that I’m using the “IRequestReplyRouter” contract since I have a request/reply service being fronted by the Routing Service.

    <services>
          <service behaviorConfiguration="RoutingBehavior" name="System.ServiceModel.Routing.RoutingService">
            <endpoint address="" binding="basicHttpBinding" bindingConfiguration=""
              name="RouterEndpoint1" contract="System.ServiceModel.Routing.IRequestReplyRouter" />
          </service>
        </services>
        <behaviors>
          <serviceBehaviors>
            <behavior name="RoutingBehavior">
              <routing routeOnHeadersOnly="false" filterTableName="filterTable1" />
              <serviceDebug includeExceptionDetailInFaults="true"/>
              <serviceMetadata httpGetEnabled="true" />
            </behavior>
          </serviceBehaviors>
        </behaviors>
    

    Once we build and deploy the service to IIS 7, we can browse it.  Recall that in our global.asax file we defined a URL suffix named “router.”  So, to hit the service, we load our web application and append “router.”

    2009.12.16router02

    As you’d expect, this WSDL tells us virtually nothing about what data this service accepts.  What you can do from this point is build a service client which points at one of the actual services (e.g. “HelloServiceMan”), but then switch the URL address in the application’s configuration file.  This way, you can still import all the necessary contract definitions, while then switching to leverage the content-based routing service.

    So, the Routing Service is pretty cool.  It does a light-weight version of what BizTalk does for routing.  I haven’t played with composite filters and don’t even know if it’s possible to have multiple filter criteria (like you can with a BizTalk Server subscription).  Either way, it’s good to know how to actually deploy this new capability in an enterprise web server instead of a console host.

    Anyone else have lessons learned with the Routing Service?

    Share

  • Interview Series: Four Questions With … Brian Loesgen

    Happy December and welcome to my 15th interview with a leader in the “connected technology” space.  This month, we sit down with Brian Loesgen who is a prolific author, blogger, speaker, salsa dancer, former BizTalk MVP, and currently an SOA architect with Microsoft.

    Q: PDC 2009 has recently finished up and we saw the formal announcements around Azure, AppFabric and the BizTalk Server roadmap.  It seems we’ve been talking to death about BizTalk vs. Dublin (aka AppFabric) and such, so instead, talk to us about NEW scenarios that you see these technologies enabling for customers.  What can Azure and/or AppFabric add to BizTalk Server and allow architects to solve problems easier than before?

    A: First off, let me clarify that Windows Server AppFabric is not just “Dublin”-renamed, it brings together the technologies that were being developed as code-name “Dublin” and code-name “Velocity”. For the benefit of your readers that may not know much about “Velocity”, it was a distributed in-memory cache, ultra-high performance and highly-scalable. Although I have not been involved with “Velocity”, I have been quite close to “Dublin” since the beginning.

    I think the immediate value people will see in Windows Server AppFabric is that now.NET developers are being provided with a host for their WF workflows. Previously developers could use SharePoint as a host, or write their own host (typically a Windows service). However, writing a host is a non-trivial task once you start to think about scale-out, failover, tracking, etc. I believe that the lack of a host was a bit of an adoption blocker for WF and we’re going to see that a lot of people that never really thought about writing workflows will start doing so. People will realize that a lot of what they write actually is a workflow, and that we’ll see migration once they see how easy it is to create a workflow and host it in AppFabric and expose it as WCF Web services. This doesn’t, of course, preclude the need for integration server (BizTalk) which as you’ve said we’ve been talked to death about, and “when to use what” is one of the most common questions I get. There is a time and place for each, they are complementary.

    Your question is very astute, although Azure and AppFabric will allow us to create the same applications architected in a new way (in the cloud, or hybrid on-premise-plus-cloud), they will also allow us to create NEW types of applications that previously would not have been possible. In fact, I have already had many real-world discussions with customers around some novel application architectures.

    For example, in one case, we’re working with geo-distributed (federated) ESBs, and potentially tens of thousands of data collection points scattered around the globe, each rolling up data to its “regional ESB”. Some of those connection points will be in VERY remote locations, where reliable connectivity can be a problem. It would never have been reasonable to assume that those locations would be able to establish secure connections to a data center with any kind of tolerable latency, however, the expectation is that somehow they’ll all be able to reach to cloud. As such, we can use the Windows Azure platform Service Bus as a data collection and relay mechanism.

    Another cool pattern is using the Windows Azure platform  Service Bus as an entry point into an on-premises ESB.  In the past, if a BizTalk developer wanted to accept input from the outside typically they would expose a Web service, and reverse-proxy that to make it available, probably with a load balancer thrown in if there was any kind of sustained or spike volume. That all works, but it’s a lot of moving parts that need to be set up. A new pattern we can do now is that we can use the Windows Azure platform Service Bus as a relay: externals parties send messages to it (assuming they are authorized to do so by the Windows Azure platform Access Control service) , and a BizTalk receive location picks up from it. That receive location could even be an ESB on-ramp. I have a simple application that integrates BizTalk, ESB, BAM, SharePoint, InfoPath, SS/AS, SS/RS (and a few more things). It was trivial for me to add another receive location that picked up from the Service Bus (blog post about this coming soon, really J).  Taking advantage of Azure to act as an intermediary like this is a very powerful capability, and one I think will be very widely used.

    Q: You were instrumental in incubating and delivering the first release of the ESB Toolkit (then ESB Guidance) for Microsoft.   I’ve spoken a bit about itineraries here, but give me your best sales pitch on why itineraries matter to Microsoft developers who may not familiar with this classic ESB pattern.  When is the right time to use them, why use an itinerary instead of an orchestration, when should I NOT use them?

    A: I recently had the pleasure of creating and delivering a “Building the Modern ESB” presentation with a gentleman from Sun at the SOA Symposium in Rotterdam. It was quite enlightening, to see the convergence and how similar the approaches are. In that world, an itinerary is called a “micro-flow”, and it exists for exactly the same reasons we have it in the ESB Toolkit.

    Itineraries can be thought of as a light-weight service composition model. If all you’re doing is receiving a request, calling 3 services, perhaps with some transformations along the way, and then returning a response, then that would be appropriate for an itinerary. However, if you  have a more complex flow, perhaps where you require sophisticated branching logic or compensation, or if it’s long running, then this is where orchestrations come into play.  Orchestration provides the rich semantics and constructs you need to handle these more sophisticated workflows.

    The ESB Toolkit 2.0 added the new Broker capabilities, which allow you to do conditional branching from inside an itinerary, however I generally caution against that as its one more place you could hide business logic (although there will of course be times where this is the right approach to take).

    A pattern that I REALLY like is to use BizTalk’s Business Rules Engine (BRE) to dynamically select an itinerary and apply it to a message. The BRE has always been a great way to abstract business rules (which could change frequently) from the process (which doesn’t change often). By letting the BRE choose an itinerary, you have yet another way to leverage this abstraction, and yet another way you can quickly respond to changing business requirements.

    Q: You’ve had an interesting IT career with a number of strategic turns along the way.  We’ve seen the employment market for developers change over the past few years to the point that I’ve had colleagues say that they wouldn’t recommend that their kids go into computer science and rather focus on something else.  I still think that this is a fun field with compelling opportunities, but that we all have to be more proactive about our careers and more tuned in to the skills we bring to the table. What advice would you give to those starting out their IT careers with regards to where to focus their learning and the types of roles they should be looking for?

    A: It’s funny, when the Internet bubble burst, a couple of developers I knew then decided to abandon the industry and try their hands at something else: being a mortgage broker. I’m not sure where they are now, probably looking for the next bubble J

    You’re right though, I’ve been fortunate in that I’ve had the opportunity to play many roles in this industry, and I have never been as excited about where we are as an industry as I am now. The maturing and broad adoption of Web service standards, the adoption of Service-Oriented Architectures and ESBs, the rapid onset of the cloud (and new types of applications cloud computing enables)… these are all major change agents that are shaking up our world. There is, and will continue to be, a strong market for developers. However, increasingly, it’s not so much what you know, but how quickly you can learn and apply something new that really matters.  In order to succeed, you need to be able to learn and adapt quickly, because our industry seems to be in a constant state of increasingly rapid change. In my opinion, good developers should also aspire to “move up the stack” if you want to advance your career, either along a technical track (as an architect) or perhaps a more business-related track (strategy advisor, project management). As you can see from the recently published SOA Manifesto (http://soa-manifesto.org), providing business value and better alignment between IT and business are key values that should be on the minds of developers and architects, and SOA “done right” facilitates that alignment.

    Q [stupid question]: year you finally bit the bullet and joined Microsoft.  This is an act often equated with “joining the dark side.”  Now that phrase isn’t only equated with doing something purely evil, but rather, giving into something that is overwhelming and seems inevitable such as joining Facebook, buying an iPhone, or killing an obnoxious neighbor and stuffing him into a recycling container.  Standard stuff.  Give us an example (in life or technology) of something you’ve been resisting in your life, and why you’re holding out.

    A: Wow, interesting question. 

    I would have to say Twitter. I resisted for a long time. I mean c’mon, I was already on Facebook, Live, LinkedIn, Plaxo…. Where does it end? At some point you need to be able to live your life and do your work rather than talking about it. Plus, maybe I’m verbose, but when I have something to say it’s usually more than 140 characters, so I really didn’t see the point. However, I succumbed to the peer pressure, and now, yes, I am on Twitter.

    Do you think if I say something like “you can follow me at http://twitter.com/BrianLoesgen” that maybe I’ll get the “Seroter Bump”? 🙂

    Thanks Brian for some good insight into new technologies.

    Share

  • Using UML vs. ADL (Arbitrary Diagramming Language)

    At my company, we highly encourage our architects and developers to communicate their design models through UML.  We have a standard set of diagrams that we regularly use to convey aspects of a given solution, including:

    • Component diagrams for system dependency, functional decomposition and data flow
    • Use case diagrams for business and system scenarios
    • Sequence diagrams for a timing perspective on system interactions
    • Deployment diagrams for both logical and physical representations of the hardware/software landscape

    We all know that the job of architect pretty much consists of “ask lots of annoying questions” and “draw boxes and lines.”  The downside with being so UML-centric is that UML can accidentally become the default way to draw boxes and lines that represent all sorts of things.  My boss has encouraged us to be observant for when a particular graphical representation should take a more “marketecture” approach (i.e. fancy boxes and lines in PowerPoint or Visio) vs. formal modeling in UML or BPMN.  She labeled the PowerPoint/Visio approach as using the Arbitrary Diagramming Language (ADL) method.  Seems about right.

    What’s an example of this?  I’ll give you two.  I recently had to put together a reference architecture for a project I’m working on.  My first inclination was to throw together a functional decomposition diagram (component diagram) of all the relevant functional pieces.  However, this was very early in the project lifecycle, and I knew that this diagram would be consistently referred to in both business and technical meetings.  So instead of going nuts on a UML diagram that would be utterly confusing, and potentially hacked up to represent certain ideas, I went with a PowerPoint model that has been in regular use for 5 months now.

    In another case, I’m trying to represent deployment options (incremental phased approach vs. all-at-once) for a global system.  I began this effort thinking about component diagrams, deployment diagrams, swim lanes and mashing some things together.  Again though, I’d probably have to bastardize UML and overload agreed-upon constructs in order to convey my point.  So, I went again to trusty PowerPoint and modeled out the options in a more business-friendly way.  I could create my own terminology/model without feeling guilty for screwing up standard UML.

    This way, I could convey a sequence of deployment phases (through a set of slides), which parties were involved, and the necessary interim interfaces without butchering UML.

    So when to use each modeling style?  I’d like your thoughts as well, but for me, I switch to an ADL / marketecture model when:

    • Doing early project stage diagrams to convey concepts presented to broad audiences (e.g. logical architectures, deployment diagrams, proposed data flow between systems/organizations)
    • I realize that I need to cannibalize, bastardize, overload or otherwise distort UML notation to convey a point (e.g. user experience flow, etc)

    I fire up a UML tool for modeling when:

    • I’m building lasting representations of how a system will be built and providing an accurate blueprint to the development team
    • Conveying solution aspects to solely technical teams through presentations or design documents
    • I can take a particular solution aspect and clearly convey the point via one or many complimentary UML model perspectives.

    The hard part is not stuffing so much into a single visual model as to render it useless.  There’s no shame in requiring two (or more) different perspectives on a problem.

    So there you go. Is Visio/PowerPoint/other-boxes-and-lines-tool-of-choice your first place to go when you have to diagram something for your project team or management?  Or do you try and shape and morph traditional diagramming notations to fit your needs?

  • Validating Incoming Data Using the BizTalk Business Rules Engine

    A project team recently asked me if they could use the BizTalk BRE to validate incoming data.  I asked what sort of validation we were talking about, and it came down to four areas:

    • Setting default values when the incoming fields were empty
    • Doing look-ups based on existing data and populating related fields
    • Doing concatenation of fields
    • Catching any business validation errors and recording them

    Before answering “of course it can”, I figured I’d quickly roll up my sleeves and prove that the BRE can do those things fairly easily.

    The Setup

    First, I had to get my environment set up.  This started with a BizTalk XSD schema to represent the data coming into the BRE.  In this scenario, the content is actually metadata about a physical file that arrives into the company.

    Notice that I have a “validation errors” record at the bottom with a repeating “error” element.

    Next, I have a really simple database table that can be used for lookups.  Based on providing a “study” and “product” value (which comes in via the inbound XML), I want to be able to figure out which “investigator” to add to the message.

    Next I need a .NET class to perform a few functions that the BRE doesn’t provide for me out of the box.  First, I need to be able to concatenate two strings.  Yes, it’s ridiculous that I have to write an operation to do this vs. the BRE having something built in.  Deal with it.

    public class RuleFunctions
    {
       public string ConcatValues(string input1, string input2)
       {
          return input1 + input2;
       }
    }

    Next, I need a function that can add nodes to my XML message when validation errors are discovered.  After adding references to the Microsoft.RulesEngine.dll and System.Xml, I wrote the following quick-and-dirty code.

    public void AddValidationError(TypedXmlDocument activeDoc, string err)
    {
       XmlDocument doc = activeDoc.Document.OwnerDocument;
    
       XmlNode errorRoot = doc.SelectSingleNode("//ValidationErrors");
    
       XmlElement newError = doc.CreateElement("Error");
       newError.InnerText = err;
    
       errorRoot.AppendChild(newError);
    }

    I accept a “TypedXmlDocument”, yank out the underlying XmlDocument, grab a pointer to the “ValidationErrors” record, and append a new node containing whatever error message was defined within the BRE.

    After GAC-ing that helper DLL, I’m ready to roll.  Before building my rules in the BRE, I wanted to establish a friendly vocabulary for my XML nodes, database columns and helper functions.  So, I defined a new vocabulary and created definitions for all the “get”, “set” and “function” operations that my rules required.

    Setting Default Values

    The first requirement was to be able to set default values on nodes.  This one’s pretty easy.  I just check for either an empty string or null value, and set the default value.

    Doing Lookups

    The next requirement was to take values from the inbound message, perform a lookup and fill in an empty node from the message.  In the rule below, I say that if the value in the XML message equals a value from the database, and another value also equals a value from the database, then set the XML node (Investigator Name) equal to another column in the database.

    What this generates behind the scenes when you execute the rule is this:

    So the proper T-SQL is built and executed to grab my lookup value.

    Performing Concatenation

    There’s no out-of-box string concatenation function in the BRE, so here I use the custom class I built earlier.  I want this rule to fire at all times, so my condition is set to something that will always be true (unless math itself starts failing).  I take a static file path location and then append the file name of the document coming into my company and turn that whole thing into an absolute path to the file.

    Catching and Recording Business Exceptions

    The final requirement was to detect business validation errors and record them.  So, we can use my custom built function from earlier to create rules that look for business errors and add nodes to the message itself which outline the error details.

    Remember that my custom function takes in a “TypedXmlDocument” type, so I pass the document itself into the function by dragging the root node of my schema from the XML Schemas Fact Explorer view into the operation parameter.

    The Result

    So what happens when I pass in a document that flexes all these conditions? I start off with an instance document that only has a few values.


    So I should see some default values get set, the “investigator” node set based on database lookups, the “file path” node be populated with the concatenated value, and I should see some errors at the end because nodes like “document sub type” and “site” are empty.

    To test this rule set, I’m using the built in rule tester, so I have to pass in a valid XML instance, a database connection, and a fact creator that provides the BRE with an instance of my custom .NET class.

    When the rule policy is finished executing, my input XML is changed to this:

    You can see that all the rules we built earlier got applied successfully.  So yes, you can use the BRE to do some pretty easy-to-maintain business validation.  This may not be a fit if you’re dealing with a nightly batch of 25,000 records, but if you are doing a messaging based solution, the BRE can do some nice work for you.

    Share

  • My Presentation from Sweden on BizTalk/SOA/Cloud is on Channel9

    So my buddy Mikael informs me (actually all of us), that my presentation on “BizTalk, SOA and Leveraging the Cloud” from my visit to the Sweden User Group is finally available for viewing on Microsoft’s Channel9.

    In Part 1 of the presentation, I lay the groundwork for doing SOA with BizTalk, and, try to warm up the crowd with stupid American humor.  Then, in Part II I explain how to leverage the Google, Salesforce.com, Azure and Amazon clouds in a BizTalk solution.  Also, either out of sympathy or because my material was improving, you may hear a few more audible chuckles.  I take it where I can get it.

    I had lots of fun over there, and will start openly petitioning for a return visit in 6 months or so.  Consider yourself warned, Mikael.

    Share

  • Interview Series: Four Questions With … Lars Wilhelmsen

    Welcome to the 14th edition of my interview series with thought leaders in the “connected technology” space.  This month, we are chatting with Lars Wilhelmsen, development lead for his employer KrediNor (Norway), blogger, and Connected Systems MVP.  In case you don’t know, Connected Systems is the younger, sexier sister of the BizTalk MVP, but we still like those cats.  Let’s see how Lars holds up to my questions below.

    Q: You recently started a new job where you have the opportunity to use a host of the “Connected System” technologies within your architecture.  When looking across the Microsoft application platform stack, how do you begin to align which capabilities belong in which bucket, and lay out a logical architecture that will make sense for you in the long term?

    A: I’m Development Lead. Not a Lead Developer, Solution Architect or Develop  Manager, but a mix of all those three, plus that I put on a variety of other “hats” during a normal day at work. I work close with both the Enterprise Architect and the development team. The dev team consists of “normal” developers, a project manager, a functional architect, an information architect, an tester, a designer and a “man-in-the-middle” whose only task is to “break down” the design into XAML.

    We’re on a multi-year mission to turn the business around to meet new legislative challenges & new markets. The current IT system is largely centered around a mainframe-based system, that (at least as we like to think today, in 2009) has too many responsibilities. We seek to use “Components of the Shelf” where we can, but we’ve identified a good set of subsystems that needs to be built from scratch. The strategy defined by the top-level management states that we should seek to use primarily Microsoft technology to implement our new IT platform, but we’re definitely trying to be pragmatic about it. Right now, a lot of the ALT.NET projects gains a lot of usage and support, so even though Microsoft brushes up bits like Entity Framework and Workflow Foundation, we haven’t ruled out the possibility to use non-Microsoft components where we need to. A concrete example is in a new Silverlight –based application we’re developing right now; we evaluated some third party control suites, and in the end we landed on RadControls from Telerik.

    Back to the question, I think over time, we will see a lot of the current offerings from Microsoft, either it targets developers, IT Pro’s or the rest of the company in general (Accounting, CRM etc. systems) implemented in our organization, if we find the ROI acceptable. Some of the technologies used by the current development projects include; Silverlight 3, WCF, SQL Server 2008 (DB, SSIS, SSAS) and BizTalk. As we move forward, we will definitely be looking into the next-generation Windows Application Server / IIS 7.5 / “Dublin”, as well as WCF/WF 4.0 (one of the tasks we’ve defined in the near future is a light-weight service bus), and codename “Velocity”.

    So,the capabilities we’ve applied so far (and planned) in our enterprise architecture is a mix of both thoroughly tested and bleeding edge technology.

    Q: WCF offers a wide range of transport bindings that developers can leverage.  What are you criteria for choosing an appropriate binding, and which ones do you think are the most over-used and under-used?

    A: Well, I normally follow a simple set of “Rules of thumbs”;

    • Inter-process: NetNamedPipeBinding
    • Homogenous intranet communication: NetTcpBinding
    • Heterogeneous intranet communication: WSHttpBinding BasicHttpBinding
    • Extranet/Internet communication: WSHttpBinding or BasicHttpBinding

    Now, one of the nice thing with WCF is that is possible to expose the same service with multiple endpoints, enabling multi-binding support that is often needed to get all types of consumers to work. But, not all types of binding are orthogonal; the design is often leaky (and the service contract often need to reflect some design issues), like when you need to design a queued service that you’d eventually want to expose with an NetMsmqBinding-enabled endpoint.

    Often it boils down to how much effort you’re willing to put in the initial design, and as we all (hopefully) know by now; architectures evolves and new requirements emerge daily.

    My first advice to teams that tries to adapt WCF as a technology and service-orientation, is to follow KISS – Keep It Simple, Stupid. There’s often room to improve things later, but if you do it the other way around, you’ll end up with unfinished projects that will be closed down by management.

    When it comes to what bindings that are most over- and under-used, it depends. I’ve seen someone that has exposed everything with BasicHttpBinding and no security, in places where they clearly should have at least turned on some kind of encryption and signing.

    I’ve also seen highly optimized custom bindings based on WSHttpBinding, with every small little knob adjusted. These services tends to be very hard to consume from other platforms and technologies.

    But, the root cause of many problems related to WCF services is not bindings; it is poorly designed services (e.g. service, message, data and fault contracts). Ideally, people should probably do contract-first (WSDL/XSD), but being pragmatic I tend to advice people to design their WCF contracts right (if in fact, they’re using WCF). One of the worst thing I see, is service operations that accepts more than one input parameter. People should follow the “At most one message in – at most one message out” pattern. From a versioning perspective, multiple input arguments are the #1 show stopper. If people use message & data contracts correctly and implements the IExtensibleDataObject, it is much easier in the future to actually version the services.

    Q: It looks like you’ll be coming to Los Angeles for the Microsoft Professional Developers Conference this year.  Which topics are you most keen to hear about and what information do you hope to return to Norway with?

    A: It shouldn’t come as a surprise, but as a Connected Systems MVP, I’m most excited about the technologies from that department (Well, they’ve merged now with the Data Platform people, but I still refer to that part of MSFT as Connected Systems Div.). WCF/WF 4.0 will definitely get a large part of my attention, as well as Codename “Dublin” and Codename “Oslo”. I will also try to watch the ADFSv2 [Formerly known as Codename “Geneva”] sessions. Apart from that, I hope to use a lot of time talking to other people. MSFTies, MVPs and other people. To “fill up” the schedule, I will probably try to attend some of the (for me) more exoteric sessions about Axum, Rx framework, parallelization etc.

    Workflow 3.0/3.5 was (in my book) a more or less a complete failure, and I’m excited that it seems like Microsoft has taken the hint from the market again. Hopefully WF 4.0, or WF 3.0 as it really should be called (Microsoft product seems to reach maturity first at version 3.0), will hopefully be a useful technology that we’ll be able to utilize in some of our projects. Some processes are state machines, some places do we need to call out in parallel to multiple services – and be able to compensate if something goes wrong, and other places do we need a rule engine.

    Another thing we’d like to investigate more thorough, is the possibility to implement claims-based security in many of our services, so (for example) can federate with our large partners. This will enable “self service” of their own users that access our Line of Business applications via the Internet.

    A more long term goal (of mine, so far) is definitely to use the different part of codename “Oslo” – the modeling capabilities, the repository and MGrammar – to create custom DSLs in our business. We try to be early adopters of a lot of the new Microsoft technologies, but we’re not about to try to push things into production without a “Go-Live” license.

    Q [stupid question]: This past year you received your first Microsoft MVP designation for your work in Connected Systems.  There are a surprising number of technologies that have MVPs, but they could always use a few more such as a Notepad MVP, Vista Start Menu MVP or Microsoft Word “About Box” MVP.  Give me a few obscure/silly MVP possibilities that Microsoft could add to the fold.

    A: Well, I’ve seen a lot of middle-aged++ people during my career that could easily fit into a “Solitaire MVP” category 🙂 Fun aside, I’m a bit curious why Microsoft have Zune & XBox MVP titles. Last time I checked, the P was for “Professional” I can hardly imagine anyone who gets paid for listening to their Zune or playing on their XBox. Now, I don’t mean  to offend the Zune & XBox MVPs, because I know they’re brilliant at what they do, but Microsoft should probably have a different badge to award people that are great at leisure activities, that’s all.

    Thanks Lars for a good chat.

  • Win a Free Copy of my Book

    So Stephen Thomas is running a little competition to give away a copy of my recent book.  Stephen calls out the details in a blog post, but basically, he’s looking for a great BizTalk tip or trick, and will award the book to the best submission.  You’ve got a week to respond.

    Stephen is running a very appropriate contest for a book like this.  It’s a good thing that HE’S doing this and not me, since my contest would something more like “whoever can first take a picture of themselves shaving a panda” or “whoever sends me the largest body part via FedEx overnight shipping.”  So thank yourselves for small favors.