Jeff W. Barnes

Ramblings on C#, WCF, and random .NET

April 2007 - Posts

How To Know Your Presentation Sucks

I picked this up from Joe Healy's blog: http://www.youtube.com/watch?v=qZOL878CwfM

Reminder: TechMixer Tomorrow Night

Just a reminder that the next Birmingham TechMixer will be held tomorrow night.  Check my previous post for details.  Don't miss out on this great networking opportunity.  If you make it, be sure to drop by the Birmingham .NET User Group table and we can chat about WCF or some other form of geek speak!

I hope to see you there. 

WCF: Your Proxy Can Only Fault Once

Quite often, one instance of a service proxy will be created and reused for multiple service invocations.  Sometimes this single instance may even be shared across an entire client application.  However, many developers overlook the what happens if a fault occurs between service calls for a proxy that is used more than once.

A proxy can no longer be used for service invocations once a fault has occurred.  This is due to the implementation of the interface ICommunicationObject.  It defines the contract of the state machine for any objects that involve communication within WCF.  This applies to channels, factories, listeners, service hosts, and so forth.  The state machine is responsible for handling the transition of communication state.  For example, it specifies whether the communication object opened, closed, etc.

When a fault occurs, the state of the communication object is set to faulted.  Once a communication object has entered the faulted state, it cannot recover.  This can pose a problem for a proxy instance that is reused.  For example, let's say that a proxy has been instantiated and used to invoke a service operation that results in an error.  This will cause the proxy to transition to a faulted state.  If another service operation is invoked via the same proxy instance, it will result in an exception since the proxy is in an invalid state.

So, how do you avoid this situation? There are a couple of options. 

  1. Subscribe to the Faulted event of the communication object. 
  2. Check the State property of the communication object before executing a service operation.

By using one (or both) of these approaches, it is possible to detect the state of a communication object is faulted and avoid an exception.  Rather than reusing the invalid communication object, a new instance must be created.  It should be emphasized that calling the Close method on an faulted communication object will result in an exception.  To transition a faulted communication object to the closed state, it is necessary to execute the Abort method. 

Posted: Apr 24 2007, 12:43 PM by jeff.barnes | with 1 comment(s)
Filed under:
Speaking at Huntsville User Group on May 21

If you will be in the Huntsville, AL area on Monday, May 21st, feel free to drop by the Huntsville New Technology Users Group meeting.  Check the website for driving directions and complete details.

I will be delivering a presentation entitled "Introduction to WCF: Fundamental Concepts for Developers".  It will be similar to the introductory WCF presentation that I gave at code camp.  However, the Huntsville User Group allows for a longer presentation (around 90 mins to 2 hrs).  So, I intend to take advantage of it to provide some thorough coverage of the core concepts. 

A lot of information will be packed into the allotted time.  We will discuss what exactly is WCF, the general architecture, and drill down into the fundamentals.  Specifically, we will examine contracts, bindings, behaviors, and hosting.  I will also demonstrate some utilities such as the WCF Configuration Editor and the Service Trace Viewer. 

If you are interested in WCF or just curious about the technology, this will be a great opportunity to learn about it and enjoy some free pizza at the same time.

I hope to see you there.

Congratulations David Silverlight

Earlier this week, Microsoft made the big announcement that WPF/E had been renamed to Silverlight.  Unless you have been in a parallel universe, I imagine you have already heard about it.  However, it wasn't until today that I found out the really interesting part of this announcement. 

It turns out that Microsoft Silverlight is actually named after David Silverlight.  When I first read about it, I thought it was a joke.  It sounded just like some kind of practical joke that David would try to pull off due to the coincidence that it matches his last name.  After further investigation, it appears to be the truth.  Several people in the blogosphere have already been chatting about it.  Check out Wally and The Elder's take on it.

If you don't know of David Silverlight, he is an extremely busy guy.  David is the mastermind behind numerous sites such as: xmlpitstop.com, community-credit.com, nonprofitways.com, and others.  I first met David at the Alabama Code Camp in Huntsville, AL back in April 2006.  He was quite a character.  It was a lot of fun hanging out with him during that weekend, and I keep waiting for another opportunity to meet up with him.  You can read his account of how the product name came to be here.

It still seems hard to believe.  I keep waiting for David to post something entitled "Ha Ha...Everyone Fell For It".  At any rate, congratulations are in order for this awesome achievement.  David devotes a lot of time to the community and it is cool to see Microsoft recognize his efforts...even if it does make me insanely jealous.  I mean...how many people do you know that actually have a product named after them? 

Gratz David!  This is a very cool honor!

Posted: Apr 18 2007, 03:22 PM by jeff.barnes | with 4 comment(s)
Filed under:
Upgraded to Community Server 2007

In case you haven't noticed, I took the plunge and upgraded the site to Community Server 2007.

I have to give props to Telligent for another seamless upgrade.  The upgrade process was easy to follow, and I encountered no errors or unexpected issues.  As far as I can tell, everything seems to be in working order.

My only complaint is that I had to purchase a Personal Edition license due to the number of photo galleries that I host for my family.  The licensing model has been modified to place a restriction on the number of forums, galleries, blogs, and such under the Express Edition.  However, I can understand their business reason for the need to do so.  Besides, as much as I use Community Server, it isn't going to kill me to support the product my buying a $99 license.

I haven't had time to look at everything that has changed.  The most obvious new feature is the new theming engine.  Due to some changes from 2.1, I have lost some of my customizations for my blog theme.  Over the next week or so, I will take a look at the new theme engine and make a few tweaks.  Or, I may just decide to use it as an opportunity to give the site an entirely new look. 

At any rate, I continue to recommend Community Server as an excellent platform.

WCF: How to Allow Impersonation for Operations

I recently received a question from someone having some trouble with impersonation:

"When I set the attribute impersonateCallerForAllOperations="true" in the web.config files, I obtain an InvalidOperationException saying that the operation does not allow impersonation."

Fortunately, this is an easy problem to solve. 

There are three impersonation options for operations in WCF that are encapsulated by the enumeration System.ServiceModel.ImpersonationOption:

  1. Allowed - Impersonation is supported when credentials are available and ImpersonateCallerForAllOperations is set to true.

  2. Not Allowed - Impersonation is not supported and an exception will occur if ImpersonateCallerForAllOperations is set to true.

  3. Required - Impersonation is required.  It is not optional and an exception will occur if the credentials are not available or ImpersonateCallerForAllOperations is set to false.

By default, WCF applies Not Allowed as the impersonation option for a given operation.  In order to enable impersonation, it is necessary to specify Required or Allowed via an OperationBehavior as shown below:

[OperationBehavior(Impersonation = ImpersonationOption.Allowed)]

If you separate your contract and implementation (and I hope you do), keep in mind the OperationBehavior cannot be applied to the contract.  It has to be applied to the implementation.  Rather than placing it on the appropriate method in your interface, it would be placed on the appropriate method in the class that implements the interface.  In other words, it goes with your service implementation rather than your service contract.

It is also necessary to set the ImpersonateCallerForAllOperations property to true in the Service Authorization Behavior.  The easiest way to accomplish this is by creating a behavior in your configuration file and referencing it from your service.  An example is shown below:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="MyBehavior">
          <serviceAuthorization impersonateCallerForAllOperations="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service behaviorConfiguration="MyBehavior" name="MyService">
        <endpoint 
          address="service" 
          binding="wsHttpBinding" 
          name="MyHttpBinding"
          contract="MyServiceContract" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8000/myService/" />
          </baseAddresses>
        </host>
      </service>
    </services>
  </system.serviceModel>
</configuration>

This should get your impersonation up and running.

Posted: Apr 16 2007, 06:43 PM by jeff.barnes | with no comments
Filed under:
Alabama Code Camp Slides

Today was the Alabama Code Camp in Mobile, AL.  Considering the weather, we had a strong showing of 100 people at the start of the day.  I have to give props to Doug Greene and Matt Hughes from the Lower Alabama .NET User Group.  They did an awesome job organizing the event.

I had a great time meeting up with some of the other speakers from across the region: Joe Healy, Doug Turnure, Jim Wooley, Keith Elder, and the infamous Wally McClure.  It was a reunion of sorts since it was the first time I had seen some of these guys in quite a while.  There were some excellent geek conversations and some new catch phrases that

I presented a session entitled: "Introduction to WCF: Fundamental Concepts for Developers".  It covers a lot of material in a short amount of time.  Unfortunately, I lost about 15 minutes of my 70 minutes session due to problems with the projector.  It forced me to rush through some of the material in order to complete on time, but I still had quite a few people that told me they enjoyed it.

You can download the code and slides here.

Next Birmingham TechMixer Scheduled

Birmingham TechMixer 3.0 has been scheduled for Tuesday, May 1st from 5:30 PM to 8PM.  It will be held again at the McWane Science Center in downtown. 

In case you aren't familiar with what TechMixer is all about, it is essentially a large networking event for the technology professionals in the greater Birmingham area.  There is usually a strong representation of the local area user groups as well.  It is a great way to meet other professionals in the area.  And, you might just find a user group that caters to one of your specific interests.  As an added bonus, there is an abundant supply of great finger foods as well as a cash bar.  You can get all of this for the reasonable price of absolutely free!  There is no fee to attend the event.

The last two events were a lot of fun.  If you haven't been to one of the previous events, make sure you attend this time! 

Check out the website for additional information.  There are links to photos from the previous events as well as registration. http://www.TechMixer.org

I will see you there.

WCF Performance Whitepaper on MSDN

Back in February, there was an interesting whitepaper published on MSDN regarding the performance of WCF in comparison to the previous technologies: ASMX, .NET Remoting, MSMQ, and Enterprise Services.  I just learned about it a few days ago.  It apparently took a month or so to start gaining momentum around the web.

Since this is a frequent topic of discussion for folks interested in adopting WCF, I thought I would pass along the link.  It is certainly a good read if you are curious about the topic.  I won't regurgitate all of the information here, but it essentially illustrates that WCF performance is superior to the previous technologies other than certain scenarios under Enterprise Services.  It did not get into P2P performance of WCF, but it would be highly dependent upon the configuration anyway.  (Hmm...sounds like something fun to do when I have a little time to kill.)

Here are the goods: http://msdn2.microsoft.com/en-us/library/bb310550.aspx

Enjoy!

Posted: Apr 05 2007, 12:01 AM by jeff.barnes | with no comments
Filed under: ,
More Posts Next page »

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