Jeff W. Barnes

Ramblings on C#, WCF, and random .NET

February 2007 - Posts

WCF Configuration Editor

If you are already familiar with the WCF Configuration Editor, this post isn't for you.  If you have no idea what I am talking about, please keep reading.

Unless you are a masochist or simply possess an exceptional love for angle brackets, the act of creating and modifying xml configuration files isn't exactly fun.  Sure, it isn't a big deal to modify an app.config to include a few key-value pairs in the appSettings section.  However, if you find yourself deep in the structure of a particular configuration section dealing with some obscure attributes, it can become a real pain.  Granted, it became significantly easier to do this sort of thing with the introduction of xml intellisense in Visual Studio 2005, but it got even easier with .NET 3.0 for WCF service configurations.

With the .NET 3.0 SDK, a utility was included to edit WCF configuration files via a GUI.  This little utility can be rather handy for people (like me) that don't particularly enjoy modifying deep xml configuration structures by hand.  Using the utility, it is possible to modify any aspect of a WCF configuration.  Now, there are times when it is overkill to use a GUI to make a simple configuration change.  But, it is quite useful for some of the more advanced configuration scenarios.

The utility is accessible from the context menu when you right click on a configuration file from the Solution Explorer in Visual Studio.  Simply select the "Edit WCF Configuration" menu option, and away you go.

The easiest way to get a feel for what this utility can do is to play around with it.  For a brief example, let's use it to create the custom Http Binary binding I posted about last week.

Right click on the Bindings folder of the Configuration pane and select the context menu option "New Binding Configuration".  A dialog window will appear that prompts you to select a binding type.  For this example, we are going to create a custom binding.  So, select the customBinding option.

This will create a new custom binding pane with the possible configuration options.  Notice the Binding Element Extension Position section in the lower right corner of the utility.  This is where binding elements can be added, removed, and re-ordered for the custom binding.  The utility adds default binding elements httpTransport and textMessageEncoding.  Remove the textMessageEncoding and replace it with binaryMessageEncoding.  Also, add a reliableSession binding element at the top position.  Remember the order is significant since it will dictate the binding element position in the communication stack.  Change the name of the binding to NetHttpBinding.

Finally, the applicable service endpoint must be configured to use the custom binding.  Expand the services folder.  Under the applicable service, expand the endpoint folder.  For the http endpoint, set the Binding to customBinding and the BindingConfiguration to NetHttpBinding.  This instructs the endpoint to use the previously configuration custom binding.

Note: This example was based on a service and endpoint already being defined in the service configuration.  If they do not already exist in the configuration, it will be necessary to create the service and endpoint as well.

Whether this is a useful tool to avoid manually modifying service configurations or simply an unnecessary tool that just slows you down, only you can be the judge.  Personally, it is handy to me when dealing with complicated service configurations.  But, different strokes for different folks.

Later this week, I will be posting about using the service trace viewer to get a closer look at what is going on with your service.  It will touch on the WCF Configuration Editor for the purpose of quickly enabling the diagnostics output.

Posted: Feb 28 2007, 01:10 AM by jeff.barnes | with 3 comment(s)
Filed under:
Finally Received Programming WCF Services

I got home from work this evening to discover that my copy of Programming WCF Services by Juval Lowy has finally arrived.  I've had it pre-ordered since mid-December.  It was originally supposed to ship at the first of the month, but there was a delay.  Regardless, I am very pleased to finally have my hands on a copy of it.

As soon as I finish it, I will be sure to post a review.  I have high expectations for this title considering the reputation of the author and his immense knowledge of WCF.

Speaking of books....I have agreed to serve on the technical review panel for the manuscript of an upcoming WCF book.  This is a new experience for me, but it is a welcome one.  Both WCF and assisting the greater developer community are of great significance to me.  By participating in this review panel, I feel like it is a good opportunity to simultaneously make a small contribution to each one.

Who knows...if this goes well, it might finally give me the drive to author my own book...as if I didn't have enough to do already. ;p

Posted: Feb 27 2007, 11:24 PM by jeff.barnes | with no comments
Filed under:
WCF: Enable Binary Encoding Over Http

It is fairly common knowledge that the NetTcpBinding in WCF provides the most efficient communication between a client and service that exist on separate machines.  The default binary encoding and TCP transport is difficult to beat in terms of transfer speed.

However, TCP is sometimes not an option due to firewalls or other prohibiting factors.  In those situations, HTTP is typically the transport of choice.  Unfortunately, the default HTTP bindings in WCF do not allow binary encoding.  With the default bindings (BasicHttpBinding, WsHttpBinding, and WsDualHttpBinding), you are limited to text or MTOM encoding.

If the client and service are both running on the WCF platform, it is still possible to leverage the benefit of binary encoding.  The ability to do so requires a custom binding.  There are two ways to create a custom binding:

  1. Build a custom binding class by inheriting from the Binding class.
  2. Specify a custom binding in the WCF configuration

The first option is useful when you want to limit the options of the binding.  For example, you only want to allow the use of certain encoders or require reliable sessions.  The custom binding implementation validates only the allowed options are used.  It can also be compiled into an assembly for easy distribution.

The second option is achieved by simply manipulating the service configuration.  However, there is no way to enforce a specific range of configuration values.  Anyone with access can modify the configuration to their liking.  Deployment can also become an issue since the client must have a corresponding configuration in order to construct a matching communication stack.  This can be handled more gracefully when a proxy and configuration file are automatically generated via SvcUtil.exe.  However, it requires the client having access to the metadata exchange. 

There is a good example of implementing a custom binding for binary encoding with HTTP on the WCF community site.  It can be found here.  Although it was based on a CTP version of WCF, the concept is still applicable to the official release.

Below is an example of how to enable a custom binding via the service configuration file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <bindings>
      <customBinding>
        <binding name="NetHttpBinding">
          <reliableSession />
          <compositeDuplex />
          <oneWay />
          <binaryMessageEncoding />
          <httpTransport />
        </binding>
      </customBinding>
    </bindings>
    <services>
      <service name="MyService">
        <endpoint
          address="http://localhost:8001/myService/"
          binding="customBinding"
          bindingConfiguration="NetHttpBinding"
          contract="MyServiceContract"
          name="HttpBinding" />
      </service>
    </services>
  </system.serviceModel>
</configuration>

The custom binding is defined within the customBinding element of the configuration.  It should be emphasized the order of the binding elements within the custom binding are important.  The order in which they appear within the binding is the order in which they are placed within the communication stack.

Within the service element, an endpoint is defined that used the custom binding.  In order for a client to consume the service via this endpoint, it must have a corresponding configuration to construct a channel stack that uses the custom binding.

Posted: Feb 22 2007, 03:11 PM by jeff.barnes | with 1 comment(s)
Filed under:
Reflector 5.0 Released

I have been trying to avoid reposting content that is already circulating the blogosphere, but this is a particularly useful announcement that is deserving of maximum exposure.

Late last night, Lutz Roeder released the latest version of Reflector.  He has added several cool features.  Rather than going into all of the details myself, I will defer to Scott Hanselman since he has already written a great post that provides one of the best breakdowns I have seen regarding the capabilities of the tool. 

By now, I would like to think that every .NET developer is aware of the existence of this utility.  Unfortunately, I doubt every .NET developer is aware of the utility's complete capabilities.  If you are one of these people, take five minutes to educate yourself about Reflector.  Reaping the benefits of what it can do for you is well worth such a small investment.

WCF Demo: Duplex Operations and UI Threads

I have posted my first WCF demo in this new series I am attempting.  This one focuses on duplex operations and some of the quirks that can arise when interacting with UI threads.  Due to the length, I have posted it as an article rather than a blog entry.  Most likely, all of my future demos will be posted in a similar fashion to avoid bogging down the RSS feed with so much content.

UPDATE:  I have also posted the article on Code Project.

UPDATE: Since I intend to begin writing articles on a regular basis, I am going to exclusively use Code Project for hosting them.  I will make a blog post with a link to the article when a new one has become available.  This will greatly assist me with editing and code corrections by only having to make changes in one location.  Consequently, I have deleted the version of the article that was hosted on my site.  Once I have a few articles, I will setup a table of contents page to better organize my articles on Code Project.

Posted: Feb 20 2007, 01:43 AM by jeff.barnes | with no comments
Filed under: ,
100th Post

Drumroll please...

This is the one hundredth post I have made since starting this blog back in October 2005. 

It is depressing to know that it took me that long to reach the 100 mark.  Granted, I didn't really do very much with this blog for the first 4 to 6 months after its debut.  However, I think the quality and frequency of posts has dramatically improved since that time.  But, there is still work to do.

As part of my New Years Resolution, I have been attempting to make a minimum of two useful posts each week.  Now, the word "useful" is fairly open to interpretation, but I think I have managed to stick to it...for the most part. 

Blogging on a regular basis is not really that difficult.  Unfortunately, blogging useful information on a regular basis is extremely difficult (at least to me).  It's not a problem to come up with material to post, but there is a significant amount of time involved with writing the posts, creating code examples, and structuring it in a manner that is easy to digest.

So, you may be wondering why do it if it is so much trouble?  Well, it is something that I enjoy.  And, it gives me an excuse to dig deeper into technologies that interest me.  Besides, there is the added bonus of occasionally posting something that actually helps someone.

Speaking of useful information, I will be posting an article and demo about WCF Callback Contracts within the next day or two.  I would like the focus of my blog to be centered around WCF with a dusting of general architecture, design patterns, and other fun stuff.  My topics have been a bit scattered lately, and I want to get back to more meaty material on what really interests me.

I am going to attempt to start posting at least one WCF demo a week.  It will likely vary in quality from week to week due to time constraints, but I want to start pushing out more code examples.  If there is a specific topic in WCF that you would like to know more about, send me a message and I will try to do a post on it.

Posted: Feb 16 2007, 07:16 PM by jeff.barnes
Filed under:
Community Server 2007 Beta 1

Well, the news is out as of yesterday that Community Server 2007 Beta 1 has been released for download.  Telligent continues to push forward with improving the Community Server platform. 

There are a large number of anticipated features with this release.  I am most interested in Chameleon, which is the code name for the new theme engine.  Supposedly, it will dramatically simplify the process of creating and customizing skins.  It will be possible to dynamically edit several aspects of the skin by directly interfacing with your website.  There will also be a feature for easily importing/exporting custom skins, including any custom images, making it simple to share with others.

Although I am anxious to see all of the changes for myself, I am not up for the potential issues of running the beta for this site.  When it is officially released later this year, I will be one of the first to download and install.  For now, CS 2.1 will just have to do.

LitwareHR - SaaS Sample Application

Late last week, Microsoft released a sample application to demonstrate some of the best practices in building SaaS (Software as a Service) applications.  I downloaded the code over the weekend, but it was tonight before I finally had a chance to load up the solution and give it a glance.

My first impression was...wow!

As emphasized in the accompanying documentation, it does not completely illustrate all possible aspects of SaaS architecture.  However, it  is still a rather thorough example.  I am very impressed with the amount of quality code provided in the solution.  They also deserve props for the documentation.

I particularly like the way it demonstrates an efficient approach for structuring the solution.  It has some similarities to the way WCF Service Factory solutions are constructed, but I prefer the clarity of the approach used by the SaaS demo.  Furthermore, there is a clean separation between specific business services from the actual system runtime services. 

At any rate, I really like the sample based on my initial review.  As I continue to digest the code, I will probably post a few more thoughts.  If you are doing any work in the SaaS domain (or just want to learn more about it), you definitely need to take a look at this sample.

Source Code and Documenation: http://msdn.microsoft.com/architecture/saas/sampleApp

CodePlex Project: http://www.codeplex.com/litwareHR

Self Evaluation: Is Your Career on Track?

It's 8:15 AM.  You are sitting at your desk sipping on a fresh cup of coffee (or favorite caffeinated beverage).  You fire up your RSS reader and begin to scan through the posts from some of your favorite blogs.  Suddenly, you notice a particular post that covers some technology that you are very passionate about.  As you begin reading, you become completely absorbed with the material.  You get excited about the prospect of applying the technology or solution to address some problem.  Then, it hits you...

There is no way in hell you are ever going to be able to use this technology at your current position.

Disgusted from the realization, you close your RSS reader and begin some mundane task that causes you to start having thoughts about strangling yourself with the cord to your keyboard due to an acute case of boredom.

Have you ever found yourself in a similar situation?  The chances are that you have.  At some point your career, you will likely find yourself questioning why you are still at your current job. 

It is imporant to self-evaluate on a regular basis to verify your current position is the right fit for your long-term career objectives.  Every now and then, it's good to take a step back and ask yourself:

  • Do I consistently feel challenged?
  • Am I passionate about the type of work that I do?
  • Have I recently learned anything new?
  • If so, will I get to apply this newly acquired knowledge?
  • Does this position support the achievment of my long-term career goals?

If you find that you really don't like your honest answers to the questions, it may be time to consider making a move to a new position.  Never allow yourself to become complacent with a stale job.  It is your responsibility to keep up with the pace of evolving technology and to ensure your career is on track to where you want it to go.  There is certainly nobody that will do it for you. 

The point is to avoid waking up one morning with the realization that your technical skills wasted away leaving you with the sense of feeling trapped and ultimately becoming a bitter, disgruntled employee with nobody to blame but yourself.

Is your career on track?



Disclaimer:The opinions and views expressed within this blog are solely my own and do not represent those of my employer or anyone else.