Jeff W. Barnes

Ramblings on C#, WCF, and random .NET

September 2007 - Posts

WCF: Don't Rely On Default Configuration Values

Never rely on the default values for your service configuration.  This is something that seems to bite a lot of developers that are new to WCF.  The large majority of the settings default to predetermined values intended to help create a more secure "out of the box" service.  However, many of these settings are not very conducive for scalability and performance.

Let's look at a few settings with default values that can be problematic. 

MaxConcurrentCalls is used to define a limit on the number of messages that can be processed by a service at any given time.  Another way of looking at it is the number of threads that will be available for serving requests.  The default value for MaxConcurrentCalls is 16.  Once there are 16 concurrent calls, the requests will start getting queued.  Depending upon the throughput required for your scenario, the default value may not be sufficient. 

MaxConcurrentSessions has a similar problem.  This setting places an upper bound on the number of sessions permitted by your service at any given time.  The default value is 10, which means only 10 sessionful clients would be allowed to simultaneously connect to the service.

MaxReceiveMessageSize of the WsHttpBinding specifies the maximum number of bytes allowed for a message.  The default value is a measly 65.536 bytes.  If you move very far beyond a "Hello World" WCF service, you are going to need more than 65,536 bytes for a message.  This is especially true for security configurations that have require sizable SOAP header in addition to the actual payload of the message body. 

These are just a few of the settings that you should review more closely.  Never make the assumption that WCF will auto-magically apply the configuration values that work best for your service and environment.  You should always conduct proper testing of your configuration.  Most likely, it will require a bit of tweaking to get the values just right for your particular scenario.  Failure to do so can (and often will) result in poor performance and/or scalability.

Don't get caught falsely accusing WCF of poor performance simply because you didn't properly configure the service!

Posted: Sep 27 2007, 11:15 PM by jeff.barnes | with no comments
Filed under:
Lots Coming Up in Birmingham Area

Initially, I was just going to post a reminder about an MSDN event on Thursday, but there is a lot of stuff coming down the pipe over the next couple of weeks or so in the Birmingham, AL area.

Note: All of these events are FREE!

Thursday, September 27th - 1PM to 5PM - MSDN Event
This is my son's first birthday, and it happens to be there is an MSDN event going on as well.  The subjects covered will be Silverlight, WCF, and LINQ.  It will be held at the Regal Cinemas in Trussville from 1PM to 5PM.  I'm not sure whether registration has been completely filled, but it is worth a shot if you are interested in attending.  Here is a link to the registration page.

Thursday, September 27th - 7PM to 8:30PM - Intro to VSTO
This is a special event that will occur after the MSDN event earlier in the day.  Russ Fustino  will be providing an overview of Visual Studio Tools for Office (VSTO).  If you are interested in doing any sort of Office integration, this is a presentation that you don't want to miss.  The event will be held at the Softech Development office in the Galleria Tower.  There will also be free pizza, but space is limited to the first 35 that register.  Click here for the registration page.

Thursday, October 4th - 11:30AM to 1PM - October IPSA Meeting
Are you in Email Hell?  Know someone who is?  Then make plans to attend this engaging session to learn the secrets of escaping Email Hell.   Our speaker, Craig Huggart shows how to deal with your emails in an hour a day (or less!).  Already know how?  Come anyway and share your wisdom with all of us.

This event will be held at the McWane Science Center in the Special Events Room.  Visit the IPSA web site to RSVP.

Saturday, October 6th - 8AM to 5PM  - Alabama Code Camp
The next code camp will be held at UAB.  This is an all day event with lots of interesting topics being covered.  There are still openings for speakers if you are interested or know of anyone that would be.  Breakfast and lunch will be provided.  There should also be some swag to win.  As usual, we will be have a Pub Club after the main event at a location yet to be announced.  Check out the site for more information and a link to registration.

Tuesday, October 16th - 6:30PM to 8PM - FarPoint Roadshow
FarPoint is doing a tour through some of the deep South's finest user groups, to showcase their products and get feedback from the community.  This event will be held at New Horizons and is being hosted by both Birmingham .NET User Group and Birmingham Software Developer Association.  For those that are interested, there will be a dinner meeting place planned for somewhere after the event.

Birmingham Startup Weekend

For those of you that haven't heard, there is an upcoming event in the Birmingham area known as Startup Weekend.  It is essentially an effort to bring together some of the most talented people in the area to select a business concept, break into teams, and develop the product over the course of a weekend.  If all goes as planned, there will be a new business with a new product at the end of the weekend.

If this sounds interesting to you, head over to http://www.birminghamstartup.com and http://birminghamstartup.wordpress.com for more information.  Some of the details haven't completely been fleshed out, such as the development platform that will be used for the solution.  I realize this will be a big factor for many of you that would like to participate (myself included).  Regardless, I would encourage you to register and give your feedback. 

This is an extraordinary opportunity to network with some talented individuals and play an important role in the development of not only a product, but also a company.

VS2008: Add Service Reference Is Greatly Improved

If you have worked much with WCF in the Visual Studio 2005 environment, you are probably aware of the Add Service Reference option in the context menu when a project is right clicked in Solution Explorer. 

When the menu option is clicked, it launches the Add Service Reference Dialog, which is a very simple prompt that uses svcutil in the background to generate a service proxy, configuration file, and adds a reference to System.ServiceModel for the project. 

Unfortunately, the simplicity of the input forces VS2005 to use a set of default options for svcutil.  As I have blogged in the past, svcutil has a large number of options.  If you need to use any of those options, you must resort to the command line utility rather than using Visual Studio.

Fortunately, this has been addressed in Visual Studio 2008.  There is a brand new Add Service Reference dialog.  The initial dialog has been enhanced a bit...

 

But, the really nice part is hidden until you click on the Advanced button of the dialog.  It launches a separate window that enables you to specify quite a few options for svcutil.  For example, it is now possible to generate a proxy that contains asynchronous methods from within Visual Studio.  There are also options to specify the type used for collections and dictionaries as well as any referenced types and assemblies.

There are still a lot of options that are only accessible by directly using svcutil via the command line.  However, VS2008 has addressed most of the major complaints from developers that like to use Visual Studio for managing their proxies.

Posted: Sep 18 2007, 01:06 AM by jeff.barnes | with no comments
Filed under:
Cool Nerd King

I finally caved and took the Nerd Test that has been circulating a lot of the technical blogs. My score in the history/literature section is a reminder to me that all I ever really read are technical books. 

At any rate, I am a apparently a "Cool Nerd King". What are you?

NerdTests.com says I'm a Cool Nerd King.  What are you?  Click here!

Posted: Sep 14 2007, 05:13 AM by jeff.barnes | with no comments
Filed under: ,
WCF 3.5: Hosting Services for WebGet

In my last post, I provided an overview of using the new WebGet attribute to map an HTTP GET operation to a specific method.  However, I didn't cover the the necessities for hosting a service that uses this functionality. 

If you intend to expose multiple endpoints that use more than one binding, it is necessary to use the traditional approach of ServiceHost.  In order for WebGet to work correctly, an endpoint that uses the new binding named WebHttpBinding is required.  As usual this can be done programmatically or via configuration.  Regardless of the approach that is used, the WebHttpBehavior must be applied to the endpoint that is using the WebHttpBinding.  This is a special endpoint behavior that enables the web programming model.

ServiceHost host = new ServiceHost(
    typeof(WeatherService),
    new Uri("http://localhost:8000/WeatherService"));

host.AddServiceEndpoint(
    typeof(IWeatherService),
    new WebHttpBinding(),
    "");

host.Description.Endpoints[0].Behaviors.Add(
    new System.ServiceModel.Description.WebHttpBehavior());

host.Open();

Here is the equivalent via configuration:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
   <system.serviceModel>
      <behaviors>
         <endpointBehaviors>
            <behavior name="WebBehavior">
               <webHttp />
            </behavior>
         </endpointBehaviors>
      </behaviors>
      <services>
         <service name="ServiceApplication.WeatherService">
            <endpoint 
               name="WebEndpoint"
               behavior="WebBehavior"
               address="http://localhost:8000/WeatherService"
               binding="webHttpBinding"
               contract="ServiceApplication.IWeatherService" />
         </service>
      </services>
   </system.serviceModel>
</configuration>

If you only intend to use the WebHttpBinding, there is a much easier alternative.  There is a specialized implementation of ServiceHost named WebServiceHost that does not require any configuration.  You simply specify the service type and the base uri.  It will automatically use the WebHttpBinding and WebHttpBehavior. 

WebServiceHost host = new WebServiceHost(
    typeof(WeatherService),
    new Uri("http://localhost:8000/WeatherService"));

host.Open();

To use this host in IIS, the following .svc file could be used:

<%@ 
   ServiceHostFactory="System.ServiceModel.Activation.WebServiceHostFactory"
   Language="C#"
   Service="ServiceApplication.WeatherService"
   CodeBehind="~/App_Code/WeatherService.cs" %>
Posted: Sep 13 2007, 04:00 AM by jeff.barnes | with 5 comment(s)
Filed under:
WCF 3.5: WebGet Attribute

It has been a week or so since I contributed to my series on WCF 3.5.  Hopefully, I will get things back on track this week by focusing a bit on the new features that support the REST style of web services.  Rather than going into a long winded explanation of REST, I will defer to Wikipedia's definition.  The key take away for the purpose of this post is that REST is an alternative to the WS-* protocols and SOAP.  It places more of an emphasis on Plain Old Xml (POX) and HTTP methods (or verbs). 

We will kick things off by taking a look at one of the new attributes in WCF.  For those of your REST guys, this will be one of the most commonly used attributes for your services.  It is none other than WebGet, which resides in the System.ServiceModel.Web assembly.  As the name implies, this provides a mechanism to map an HTTP GET operation to a specific method.

Let's look at a simple example and break it down:

[ServiceContract(Namespace = "http://JeffBarnes.Samples.WeatherService")]
public interface IWeatherService
{
    [OperationContract]
    [WebGet(
        BodyStyle = WebMessageBodyStyle.Bare,
        RequestFormat = WebMessageFormat.Xml,
        ResponseFormat = WebMessageFormat.Xml,
        UriTemplate = "/GetCurrentTemp/{zipCode}")]
    Temperature GetCurrentTemperature(string zipCode);
}

If you examine the code, you will see a typical service contract and operation contract.  However, the WebGet attribute has also been applied to the same method as the operation contract.  This notifies the WCF runtime that the method is a retrieval operation and can be mapped to an HTTP GET operation.  The Temperature class returned by the method is a very simple class that contains a Scale and Amount property.  It is exposed via a standard DataContract.

As you can see, there are a few parameters available in the attribute.  They are relatively self-explanatory, but let's quickly review them. 

BodyStyle
This parameter indicates whether the request and response should be wrapped with "infrastructure provided XML elements."  This wrapping can be applied to both the request and response or only one of the two.  When set to Bare, there is no wrapping provided. 

Here is an example of a wrapped response from the GetCurrentTemperature method.

<GetCurrentTemperatureResponse xmlns="http://JeffBarnes.Samples.WeatherService">
  <GetCurrentTemperatureResult xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
    <Amount>10.25</Amount> 
    <Scale>Celsius</Scale> 
  </GetCurrentTemperatureResult>
</GetCurrentTemperatureResponse>

Here is an example of a bare response from the GetCurrentTemperature method.

<Temperature 
   xmlns="http://JeffBarnes.Samples.WeatherService" 
   xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
  <Amount>10.25</Amount> 
  <Scale>Celsius</Scale> 
</Temperature>

RequestFormat and ResponseFormat
These two parameters simply specify whether the request and response will be formatted as Xml or JSON.  Since there are two separate parameters, you could potentially have the request formatted differently from the response.

UriTemplate
At last, we finally begin to see where the new UriTemplate class comes into play.  This template provides a way to map the zip code in the uri to the zip code parameter in the GetCurrentTemperature method.  The beauty of this is that WCF takes care of the dirty work.  Rather than manually parsing out parameters from a uri, WCF just hands the value to the method.  Refer to my previous post about UriTemplate for more information.

Posted: Sep 11 2007, 12:40 AM by jeff.barnes | with 5 comment(s)
Filed under:
Reminder: BUG.NET Meeting on 9/11

The Birmingham .NET User Group will be meeting on Tuesday, September 11th.  Please remember that our meeting location has changed. The meetings are now held at the New Horizons located at Beacon Pkwy, Birmingham, AL 35209.  As usual, the meeting with will begin at 6:30PM.  Here are directions. 

Todd Miranda, Chief Information Security Officer of Softech Development, will be speaking about the Microsoft Expression Suite.  

See you there.

Alabama Code Camp Registration Opened

Registration for the Alabama Code Camp has officially been opened.  Be sure to get signed up for the event, and don't forget about the Silverlight contest.  It is a great chance to demonstrate your creativity and win a Zune for the effort.  Details about the speakers and sessions should become available in the near future.

Keep an eye on the site for new information.

Reminder: IPSA Meeting on 9/13

The September meeting for the Internet Professionals Society of Alabama (IPSA) will be on Thursday, September 13th.  The meeting will be held from 12PM to 1PM at the McWane Science Center in downtown.  The presentation will be located in the Special Events Center on the 3rd floor.  There will be designated networking time from 11:30AM to 12PM prior to the beginning of the presentation.

Chris Rue, President and CEO of Black Warrior Technology, LLC,  will be discussing mobility.  He is also one of the area's newest Microsoft MVPs.  Chris was awarded MVP in the category of Microsoft Windows Small Business Server.  In his presentation, he will be talk about where mobility is now and where it is/should be going.  This will touch on several of the currently available platforms such as PalmOS, BlackberryOS, Symbian, Windows Mobile, and OSX.  It was also mentioned that he will probably talk a bit about some of the latest rumors emanating from Mountain View. 

I'll see you there.



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