Archive for January, 2008

Article Series on BizTalk and WCF: Part I, Operation Patterns

A couple months back I wrote a short post explaining some simple BizTalk Server 2006 R2 + Windows Communication Foundation scenarios.  Afterwards, I was approached by the folks at TopXML.com to write a series of articles that provided depth on BizTalk + WCF integration.

So, I’ve begun a multi-part series of articles that explain many of the core aspects of how BizTalk and WCF play together.

My first article explains the various operation patterns when BizTalk consumes a WCF service.  In this article, I touch upon dealing with complex vs. simple types, one way vs. two way operations, (custom) fault contracts, and using the WCF-WSHttp and WCF-WSCustom BizTalk adapters.

The next piece I’m publishing showcases the various WCF security configurations supported by BizTalk Server 2006 R2.  Then, I’ll demonstrate BizTalk integration with MTOM and Transactional WCF services.  Finally, I’ll finish the series with articles describing how to publish WCF services OUT of BizTalk.  Should be fun and I hope folks learn as much reading these as I did writing them.

In the meantime, if you have questions/comments/corrections on this first article, please leave a comment here.

Series Summary
 BizTalk and WCF: Part I, Operation Patterns Get the source code!
 BizTalk and WCF: Part II, Security Patterns
 BizTalk and WCF: Part III, Transaction Patterns
 BizTalk and WCF: Part IV, Attachment Patterns
 BizTalk and WCF: Part V, Publishing Operations Patterns Get the source code!
BizTalk and WCF: Part VI, Publishing Advanced Service Patterns
BizTalk and WCF: Part VII, About the BizTalk Adapter Pack Get the source code!
BizTalk and WCF: Part VIII, BizTalk Adapter Pack Service Model Patterns
BizTalk and WCF: Part IX, BizTalk Adapter Pack BizTalk Patterns

Technorati Tags: ,

MVP Shenanigans

I’m apparently being subjected to some new MVP hazing.  I received my “welcome” kit in the mail … but it was for some MOM MVP!  Then poor Tim received my kit in the mail.  This was after my online profile got mixed up for a few days.  I’m worried that the next MVP box I receive from Microsoft will be full of human hair or a frozen kidney.  Stay tuned.

BizTalk Deployment Poster Now Available

If you’re setting up a BizTalk environment, or considering growing your existing configuration, take a peek at the just-released BizTalk Scale-Out Options poster from Microsoft (hat tip: Eric).

Not sure I’d revisit this poster that often (compared to the BizTalk Capabilities poster or the Runtime Architecture poster which are both hanging in my office), but, it’s definitely worth reviewing once.

While I’m linking to stuff today, check out the latest from my buddy Victor who just wrote an epic post on cleansing data with DataFlux.  Neat stuff.

 

Technorati Tags:

Applying Role-Based Security to BizTalk Feeds From RSSBus

I recently showed how one could use RSSBus to generate RSS feeds for BizTalk service metrics on an application-by-application basis.  The last mile, for me, was getting security applied to a given feed.  I only have a single file that generates all the feeds, but, I still need to apply role-based security restraints on the data.

This was a fun exercise.  First, I had to switch my RSSBus installation to use Windows authentication, vs. the Forms authentication that the default installation uses.  Next I removed the “anonymous access” capabilities from the IIS web site virtual directory.  I need those steps done first because I plan on checking to see if the calling user is in the Active Directory group associated with a given BizTalk application.

Now the interesting part.  RSSBus allows you to generate custom “formatters” for presenting data in the feed.  In my case, I have a formatter which does a security check.  Their great technical folks provided me a skeleton formatter (and way too much personal assistance!) which I’ve embellished a bit.

First off, I have a class which implements the RSSBus formatter interface.

public class checksecurity : nsoftware.RSSBus.RSBFormatter

Next I need to implement the required operation, “Format” which is where I’ll check the security credentials of the caller.

public string Format(string[] value, string[] param)
{
   string appname = "not_defined";
   string username = "anonymous";
   bool hasAccess = false;

   //check inbound params for null
   if (value != null && value[0] != null)
   {
     appname = value[0];
     //grab username of RSS caller
     username = HttpContext.Current.User.Identity.Name;
     if (HttpContext.Current != null)
     {
        //check cache
	if (HttpContext.Current.Cache["BizTalkAppMapping"] == null)
        {
          //inflate object from XML config file
          BizTalkAppMappingManager appMapping = LoadBizTalkMappings();

          //read role associated with input BizTalk app name
          string mappedRole = appMapping.BizTalkMapping[appname];

          //check access for this user
          hasAccess = HttpContext.Current.User.IsInRole(mappedRole);

          //pop object into cache with file dependency
          System.Web.Caching.CacheDependency fileDep =
               new System.Web.Caching.CacheDependency
                   (@"BizTalkApplicationMapping.xml");
          HttpContext.Current.Cache.Insert
                   ("BizTalkAppMapping", appMapping, fileDep);
         }
        else
         {
          //read object and allowable role from cache
          string mappedRole =
               ((BizTalkAppMappingManager)
                    HttpContext.Current.Cache["BizTalkAppMapping"])
                       .BizTalkMapping[appname];

         //check access for this user
         hasAccess = HttpContext.Current.User.IsInRole(mappedRole);
          }
     }
  }
  if (hasAccess == false)
        throw new RSBException("access_violation", "Access denied.");

  //no need to return any value
  return "";
}

A few things to note in the code above.  I call a function named “LoadBizTalkMappings” which reads an XML file from disk (BizTalkApplicationMapping.xml), serializes it into an object, and returns that object.  That XML file contains name/value pairs of BizTalk application names and Active Directory domain groups.  Notice that I use the “IsInRole” operation on the Principal object to discover if this user can view this particular feed.  Finally, see that I’m using web caching with a file dependency.  After the first load, my mapping object is read from cache instead of pulled from disk. When new applications come on board, or a AD group account changes, simply changing my XML configuration file will invalidate my cache and force a reload on the next RSS request.  Neato.

That’s all well and good, but how do I use this thing?  First, in my RSSBus web directory, I created an “App_Code” directory and put my class files (formatter and BizTalkApplicationMappingManager) in there.  Then they get dynamically compiled upon web request.  The next step is tricky.  I originally had my formatter called within my RSSBus file where my input parameters were set.  However, I discovered that due to my RSS caching setup, once the feed was cached, the security check was bypassed!  So, instead, I put my formatter request in the RSSBus cache statement itself.  Now I’m assured that it’ll run each time.

So what do I have now?  I have RSS urls such as http://server/rssbus/BizTalkOperations.rsb?app=Application1 which will only return results for “Application1″ if the caller is in the AD group defined in my XML configuration file.  Even though I have caching turned on, the RSSBus engine checks my security formatter prior to returning the cached RSS feed.  Cool.

Is this the most practical application in the world?  Nah.  But, RSS can play an interesting role inside enterprises when tracking operational performance and this was a fun way to demonstrate that.  And now, I have a secure way of allowing business personnel to see the levels of activity through the BizTalk systems they own.  That’s not a bad thing.

Technorati Tags: ,

[Help] XML Serialization Result is Different in Separate Environments

Here’s one for you.  I have two Windows Server 2003 environments, and in one environment, a .NET object correctly serializes to XML, and in the next environment it does not.

Let’s set this up.  First, I have an existing schema like below where my datetime/number types are both nillable, and have a minOccurs of 0.  So, they could exist and be null, or not exist entirely.

Next, I generate a typed object for this schema using xsd.exe.  The generated class contains my schema nodes, of course, but xsd.exe also inserts these boolean “[fieldname] + Specified” variables.  Now these field accessors have the XmlIgnoreAttribute, so they don’t get included in the XML document, but rather can be used to check if a field exists.  If the value is false, the the XML serializer doesn’t include the corresponding field in the output.

So far so good.  I’ve built a really simple application that takes an XML string and loads it into my .NET object via the XmlSerializer Framework object.  On my development machine, executing this step results in a MessageBox window that shows the object properties after the Xml deserialization occurred.

 

As you can see, all the values in my original XML document converted fine, and, the “specified” fields are both set to true because the corresponding fields have values.  If I take this little application, and run it on our common development environment, I get the exact same result (I’ve also tested this on some co-worker’s machines).  However, if I run this application in our TEST environment (same OS, same .NET framework version as previously tested environments), I get the following result:

What, what, what??  I still have values present for the integer (“Age”) and datetime (“BirthDate”) but the “specified” fields are now false.  What’s the ramification?  Turning this object back into XML in this TEST environment results in this …

Yowza.  Now those fields don’t get serialized back into the XML document.  Not good.  As for solutions, the quickest one is to remove the auto-generated “specified” fields from the .NET object which results in everything serializing and deserializing just fine.  However, I don’t like mucking with auto-generated code because you have to remember what changes you’ve made for all future releases.

Thoughts as to what could cause this?  A .NET hotfix, something environmental? I’ve included my little test application here, so feel free to download and execute the quick test on your machine and post the results in the comments.

Technorati Tags:

Year in Review, MVP Status Awarded

I was going to use this, my 100th post on WordPress, and first of 2008, to highlight my favorite posts from last year.  But upon my return from vacation yesterday, I discovered that I had been granted an MVP award for my efforts in 2007, so, I also want to throw a quick thanks to the Microsoft folks.  Achieving an MVP was one of my silent goals for the year, so I’m jazzed that my contributions were considered useful enough to warrant this.

I had lots of fun learning new BizTalk things in 2007, and these were a few of the ones that I enjoyed writing the most …

This year you’ll see fewer BizTalk-related posts as I continue my descent into broad systems architecture, but, I’ll try and keep you all entertained nonetheless.

Technorati Tags: , ,


Disclaimer

Entries and comments here do not necessarily reflect the opinions, attitudes, and statements of my employer, my friends, or anyone associated with me.

Syndication

Publications

Order my new book SOA Patterns with BizTalk Server 2009 (Amazon.com, Packt Publishing)

Contact Me

Categories

Twitter Feed

Blog Stats

  • 221,744