Jeff W. Barnes

Ramblings on C#, WCF, and random .NET

July 2007 - Posts

Podcast Fever

Back in early July, I finally broke down and purchased a Zune.  On a side note, it is amazing at how many people labeled me as an honorary Blue Badge for simply owning the device.  At any rate, the main reason I bought a Zune was for listening to music at work.  My new employer doesn't permit streaming audio over the company intranet.  Although music was my primary focus, I decided to take Robert Cain's advice about podcasts. 

Robert is a big fan of .NET Rocks and other technical podcasts.  I had actually listened to a few episodes of .NET Rocks in the past, but it was very random and I never really got into a habit of listening to every show.  Well, I have officially developed an acute case of podcast fever...particularly around .NET Rocks.  As someone that tries to stay active within the developer community, it is somewhat embarrassing that I hadn't already jumped into the series.  I had no idea what I was missing.  As an added bonus, my commute seems to fly by as a result of me really getting into the discussions on the show.

Do yourself a favor.  If you are a .NET developer or have an interest in .NET at all, go subscribe to DNR (.NET Rocks) right now.  Even if you don't have an MP3 player, I strongly encourage you to invest some time in expanding your knowledge by making some time to listen to the show.  Carl and Richard do a tremendous job of keeping the content varied to attract a wide range of listeners.  Although the content doesn't always immediately apply to my current projects, it is important to stay abreast of what is going on in the .NET world.  With such a rapid rate of change in the industry, this is an easy (and cheap) way to help yourself keep up with all of it.

Here is a list of some worthwhile podcasts and screencasts that every .NET professional should at least take a look at:

Reminder: IPSA Meeting on 8/2

The August meeting for the Internet Professionals Society of Alabama will be on Thursday, August 2nd.  The meeting will be held from 12PM to 1PM at the McWane Science Center in downtown.  The presentation will be located in the Special Event Center on the 3rd floor.  There will be designated networking time from 11:30AM to 12PM prior to the beginning of the presentation.

Todd Miranda will be presenting on XAML.  He is the Chief Information Security Officer of Softech Development.  He is actively involved in the developer community and also happens to be a recepient of the Microsoft MVP award.  If you aren't familiar with XAML, it is a markup language used to describe objects in Silverlight and WPF.  Given Todd's track record of top notch presentations, this should be very informative.  Don't miss out if you are starting to venture into the world of WPF and/or Silverlight.

I'll see you there.

SvcUtil Essentials: Service Validation

This will probably be the last post in my mini-series that highlights some of the capabilities of svcutil.

How many times have you attempted to start up a service to discover there was a problem that causes a runtime error?  If you have done very much WCF development, the answer is probably quite a few.  Rather than fighting through a series of runtime errors, wouldn't it be nice to get a complete list of the problems with your service?  This is exactly one of the lesser known features of svcutil: service validation.

Before we get into exactly what it does, let's cover why it is necessary in the first place.  So, we will begin with an example.  Let's assume that you have a service contract that looks like the code shown below:

[ServiceContract]
interface IZipCodeService
{
    [OperationContract(IsOneWay = true)]
    string GetCityName(string zipCode);
}

This snippet of code contains an interface that has been decorated with the necessary attributes to expose the operations for consumption.  If you look closely, the OperationContract for the GetCityName method has set the IsOneWay property to true.  This tells the WCF runtime that caller doesn't have to wait for a return value.  As soon as the operation begins execution, control will be returned to the caller.  However, IsOneWay can only be set to true for methods that don't return any values (a void return type). 

The GetCityName method does have a return type of string.  So, it would not be legal to set IsOneWay to true for the method.  At first glance, you might tell yourself "Eh, no big deal.  It will generate a compilation error."  Unfortunately, you would be incorrect.  WCF does not have any special interface to the C# compiler (or VB.NET).  As far as the compiler is concerned, this an attribute that can only be applied to methods, which is valid in this case.  Also, the compiler only sees that IsOneWay is a boolean and can be set to true or false, which is also valid in this case.

Consequently, it is up to the WCF runtime to ensure the attribute is valid when your service is loaded.  Basically, this means you will not know whether your service contains any invalid configuration until is has been loaded at runtime.  This is why many people run into a series of errors when they simply start the project that is hosting their service for the first time.  If you use this approach to validate the service, you essentially have to correct one problem, recomplie, and try again...which can get annoying if you have several problems with the service.

This is where svcutil can make your life a bit easier.  Rather than hosting the service to allow the WCF runtime to determine whether it is valid, the command line utility can be used to do the same thing without a hosted service.  For example, the following command could be used to validate the service from the previous code snippet.

svcutil /validate /serviceName:ZipCodeService ZipCodeService.dll

The validate switch tells the command line utility that you want to perform a service validation.  The serviceName switch is used to reference the name of the service within your corresponding configuration file.  This is one of the only limitations to using svcutil for service validation.  It must have a config file in order for it to work.  If you programmatically configure your service, you will have to validate it the good ole fashioned way.  Lastly, you specify the assembly that contains the complied service. 

When the command is execute, you will see some output similar to the following:

Warning: There was an error loading the service to be validated.
    Type: JeffBarnes.Samples.ZipCodeService, ZipCodeService, Version=1.0.0.0
, Culture=neutral, PublicKeyToken=null.
    Details:Operations marked with IsOneWay=true must not declare output parameters, by-reference parameters or return values.

The Service 'JeffBarnes.Samples.ZipCodeService' was validated with no
 errors

As you can see, a warning was generated that indicates the problem we previous discussed concerning IsOneWay only being valid when there is no return type.  However, it also says the service did not contain any errors.  To be honest, I am a little fuzzy on the difference between a warning and an error.  Even though the problem is listed as a warning by the command line utility, you will get a runtime error if you attempt to host the service.

At any rate, this is another approach for validating your service that can be added to your toolbox.

Posted: Jul 27 2007, 04:00 AM by jeff.barnes | with 1 comment(s)
Filed under:
SvcUtil Essentials: Asynchronous Proxy Methods

This is the next post in my mini-series on some highlights of svcutil.

One of the most common questions I am asked that leads into a conversation about svcutil is "How do I generate a proxy with asynchronous methods?"  If you have worked very much with ASP.NET web services (ASMX), you are probably used to seeing methods in your proxy that are prefixed with Begin and End.  For example, let's say that your web service has a method named Foo.  A proxy generated by the wsdl utility (or even directly by Visual Studio) will contain a Foo method as well as BeginFoo and EndFoo methods.  If you execute the Foo method, the web service operation is invoked synchronously.  However, you can leverage the BeginFoo and EndFoo methods to asynchronously invoke the corresponding web service operation.

If you are accustomed to using these asynchronous methods, you will quickly find them to be missing from a WCF proxy that gets generated by Visual Studio.  For whatever reason, the asynchronous methods are no longer generated by default.  There is a specific switch in svcutil that is required in order to output the asynchronous methods.  Unfortunately, the switch isn't used when generating a proxy via Visual Studio.  Fortunately, it is quite simple to do via svcutil.

All that is required is adding an additional switch: /async or /a for short.

Here is an example command that will generate asynchronous methods from a service that is already running:

svcutil /t:code http://localhost/myService /out:Proxy.cs /config:Proxy.config /async

Here is a command that will generate asynchronous methods from local wsdl and xsd files:

svcutil /t:code *.wsdl *.xsd /out:Proxy.cs /config:Proxy.config /async

Posted: Jul 26 2007, 04:00 AM by jeff.barnes | with 1 comment(s)
Filed under:
SvcUtil Essentials: Generate Proxy from Compiled Code

This the next post in my short series on some of the highlights of svcutil.  Last time, I posted about the command used to generate a proxy and corresponding configuration by referencing a service that is currently running.  While useful, there will be occasions where you need to generate a proxy when the service is not running.  In those situations, another option could be using the compiled assembly that contains the service implementation to generate the proxy. 

Unfortunately, there is no single command that can be used to generate a proxy by only pointing at an existing assembly.  The process has to be broken down into two steps.

  1. Export metadata from the complied code.
  2. Use the metadata to generate a proxy.

Assume you have a complied assembly, MyServiceAssembly.dll, that contains the implementation of a WCF service.  You need to extract the metadata of the service from the compiled code.  Once the metadata has been made available, svcutil can generate a proxy in almost the same manner as a service that is running.

Export Metadata

So, how do you get the metadata out of a compiled assembly? 

svcutil /t:metadata MyServiceAssembly.dll

This command will search the assembly and export the service metadata.  It will create a WSDL file and any XSD files that are referenced by the WSDL.  To the best of my knowledge, you do not have any control over the name of the output files via svcutil.  The utility will use the namespace of the service specified in the ServiceOperationAttribute.  If no namespace has been specified, the default value of tempuri.org will be applied.

Generate Proxy with Metadata Files

Now that you have the WSDL and corresponding XSDs, a proxy can be generated using nearly the same command as when the source is a running service.

svcutil /t:code *.wsdl *.xsd /out:Proxy.cs /config:Proxy.config

If you refer to the previous post about generating a proxy from a running service, you will find the only difference to be specifying the wildcard pattern for the WSDL and XSD files.  In this case, the utility will search for WSDL and XSD files on the local machine in the given directory.  It should be noted that you are not required to use the wildcard pattern.  You can specifically list each individual file as part of the command.  This is just a slightly shorter variation if you only have the applicable files in the given directory.

 

Now you have a proxy and metadata that is ready for distribution without having a running service to generate the files.

Posted: Jul 25 2007, 01:13 AM by jeff.barnes | with 1 comment(s)
Filed under:
SvcUtil Essentials: Generate Proxy from Running Service

Even though WCF has been around for a while now, I still have a lot of people ask me about the service model metadata tool (aka svcutil.exe).  It seems as though quite a few developers find it to be rather cryptic and difficult to use.  This is probably due to the large number of switches that are available.  Given that you will likely need to use svcutil if you do very much WCF development, I have decided to post a short series on some of its capabilities. 

Before I go any further, let me emphasize something that I have said again and again in various presentations.  Even if you are using Visual Studio to directly add a service reference in your project, you are still ultimately using svcutil.  Behind the scenes, Visual Studio is invoking svcutil with the necessary switches to generate your proxy and configuration file from the service that was referenced.  If the default proxy and configuration that Visual Studio spits out is sufficient for your needs, good for you.  But, sooner or later, you will probably find that you need to leverage svcutil in some capacity.

In this post, I am going to cover the basic process for generating a proxy with svcutil.  Keep in mind there are a LOT of options available when generating a proxy, but I only intend to cover the basic concept at this point.  Later in the series, I will go over some additional options in greater details.

To generate a proxy from a service that is currently running, simply run the following command:

svcutil /t:code http://localhost/myService /out:Proxy.cs /config:Proxy.config

Obviously, you would replace the parameters with your application values.  This command simply tells the utility to generate code from the specified service url, store the proxy in a class file named Proxy.cs, and the corresponding configuration in a file named Proxy.config.  Again, your service must be running for this to work.  Furthermore, the service must provide an endpoint for the metadata exchange.  Otherwise, there is no way to query the necessary metadata that is required to generate a proxy.  If you aren't familiar with the process, I have a previous post about enabling the metadata exchange that can be found here.

It should also be noted that the default language is C#.  If you want your proxy to use VB.Net, there is an additional language switch that can be specified: /language:VB

Posted: Jul 25 2007, 12:33 AM by jeff.barnes | with 2 comment(s)
Filed under:
Current Topics of Interest (for me anyway)

Over the last few weeks, my blogging rate has been a lot lower than usual.  This is partially due to me changing jobs and moving all within the last month.  But, it can also be attributed to be doing a lot of reading (both blogs and books).  In a certain sense, you could say that I have been doing some research to get myself up to speed regarding a few areas on which I would like to focus more closely.  As such, I thought that I would post what these areas are since you are likely to see future blog posts about them. 

  • WCF

It should come as no surprise to see WCF as the first item on my list.  WCF has been of great interest to me since long before it was officially released.  Although I have slacked off a bit on many detailed posts as of late, I expect to begin posting more stuff in this area...especially as the 3.5 release approaches. 

  • Test Driven Development

I have been intermittently using nUnit for a while, but it has been mostly to facilitate the automation of general unit testing.  Even though I am a big fan of the concept of TDD, I have not really been in a situation where I was allowed to use could apply it.  Fortunately, my new position will present the opportunity to really leverage TDD.  So, I want to invest some time to prepare myself a bit in an effort to maximize the benefits.  Even though there is quite a bit of material available in this area, I will probably post a few of my personal experiences along the way.

  • Parallel Computing

Parallel computing has been a hot topic lately.  You are beginning to hear more and more about the necessity of parallel computing in order to achieve greater scalability and performance as it becomes questionable whether Moore's Law will continue to hold true.  It has always been an intriguing area to me.  I am interested in potentially leveraging parallel processing to dramatically improve the performance and scalability related to a project at my new position.  This would mostly pertain to some intensive calculations, but it could be useful for a variety of algorithms.

If any of this stuff sounds interesting to you, keep an eye out for future posts on the subjects.  Feel free to drop me a line via the blog contact form if you have any comments or suggestions. 

Become a Better Developer in 6 Months

Well, this is old news by now.  If you track many blogs in the technical world, you are probably aware of the "Become a Better Developer in 6 Months" topic that has been circulating over the last couple of weeks or so.  At this point, I imagine just about every tidbit of useful advice has been posted.  However, Robert Cain (aka Arcane Code) tagged me from his post about the topic.  As he was quick to point out, I owe him.  So, I will respond to the tag, but I am going to take a slightly different approach.  Rather than listing my specific plan, I am going to cover a few tidbits of advice to keep in mind for successfully becoming a better developer.

Challenge Yourself
This is the first step to becoming better at anything...especially software development.  There are far too many developers in the industry that just don't care about striving to be better.  Most of them are complacent with "being good enough to get the job done."  Before you can improve your development skills, you have to want to improve your development skills.  The idea is to get yourself motivated about investing some time in your skills and knowledge...or at least maintain the skills and knowledge that you already possess.  Nobody is going to do it for you.  Remember that technology changes at an insanely rapid pace.  If you want a job that doesn't require spending some time to stay abreast of advancements in the industry, I suggest you start seriously considering a career change right now.  It is your responsibility to avoid becoming obsolete.  (In case you haven't noticed, I can easily start ranting about this specific point.)

Determine Your Goals for Being a "Better Developer"
So, you have accepted the challenge to better yourself and feel motivated about doing it.  Great!  However, before you jump ten feet deep into a specific subject, you should take a few steps back to get some perspective regarding what you want to accomplish.  Are you looking to learn more about the latest technologies that have been released?  Are you interested in brushing up on some of your weaker areas?  Are you interested in becoming even more advanced in one of your stronger areas?  Are you interested in learning more about the business domain in which you work?  Perhaps, it is all of the above.  The answer will be different for every developer.  Think about what you want to get out of this experience.  You also have to consider the amount of time you will be able to commit to the effort.  Be reasonable about what you can and cannot achieve with your given schedule.  In other words, don't set yourself up for failure, which could ultimately have a negative effect.  This isn't to say that you can't aim high.  Just make sure the target is within reach. 

Tell At Least Two People About Your Goals
Mapping out a strategy to become a better developer is great, but you shouldn't stop there.  It is far too easy to set lofty goals that are tossed aside within the first month.  If you tell a couple of people about what you intend to do, it can give you that extra push to keep going.  It wouldn't be very impressive to confess that you gave up on your goals two months from now when one of those people ask you about your progress.  An even better idea is to find a buddy that wants to better himself/herself as well.  You can lean on each other for encouragement and exchanging information.  This is essentially the same idea as finding a friend for going to the gym.

Evaluate Your Progress and Adjust Accordingly
Don't wait until the sixth month rolls around to evaluate whether you have met your goals of becoming a better developer.  Give yourself an honest evaluation at various points in the process.  If you don't feel that you have been making the kind of progress that you expected, consider revising or fine-tuning your plan as necessary.  Try to avoid locking yourself into a plan as though it is written in stone.  For example, let's say that you wanted to commit to studying two hours every day.  After a few weeks, it becomes obvious that you were too aggressive and simply don't have that much time.  You might change your plan to 8 hours per week rather than a daily commitment.  At any rate, you get the idea.  Put on your agile hat and take an iterative approach to the process.  If it isn't working, make a few changes and evaluate yourself again after you give it a chance.

Keep a Good Thing Going
The sixth month finally arrives and you determine that you have met your goals.  Congratulations!  But, don't stop now.  By this point, you have developed a habitual method for continually improving your skills and adding value to your career.  Rather than saying "okay, I am done", I encourage you to keep a good thing going.  Set new goals and start the process all over again.  If you stick to it, you will see a noticeable difference in your work and ultimately career.

WCF Case Studies

Last week, one of my favorite WCF blogger's, Nicholas Allen, posted a list of WCF case studies that are available via the Microsoft Case Studies site.  In an effort to save you time searching for WCF case studies, he has hand picked fifteen different ones that are considerably involved with WCF.  I have only reviewed a few of them, but they are rather interesting.  I thought the one for Pfizer was pretty cool.  It gives me a vision of a bunch of scientists in white lab coats sitting around a computer using 3D graphs and images to analyze their experiments...compliments of WCF and WPF!

You may be thinking...great, what a waste of time.  However, I would encourage you to poke around the case study site.  Even if you are not into WCF, there are hundreds and hundreds of case studies accessible for download.  Even though most of it is very high level, it is a great way to get an idea of how others have successfully applied a particular technology to solve a problem.  You might just find the leverage you need to persuade a group to use your favorite technology on an upcoming project. 

Posted: Jul 10 2007, 09:20 AM by jeff.barnes | with no comments
Filed under: ,
Speaking in Huntsville on Tuesday

The scheduled speaker for the Huntsville New Technology Group will not be able to make it on Tuesday.  So, I will be filling in with a WCF presentation.  This will primarily be an introductory session, but I will touch on a few advanced topics as well.  I also intend to highlight some of the enhancements that will be released with .NET 3.5.

If you will be in the area tomorrow night, I encourage you to drop by and check it out. 

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.