While I was putting my demos together for Cleveland Day of .NET I discovered a very frustrating, undocumented "feature" with the way the "Add Service Reference..." option works in Visual Studio 2008.
SPOILER ALERT!
My presentation is about custom behaviors, and one of my examples in an implementation of IInstanceProvider applied as an IServiceBehavior and added to my service runtime via code. I've done this a dozen times before with no issue, but this time something was amiss...
I wrote my code, fired up my application and saw the behavior "appear" to bind to my runtime. I ran my client and the call to the service worked. The only problem is that my behavior was not executed.
I had no idea what I could have done wrong. Like I said, I've done this dozens of times before with no issue. I went back and studied those old applications. Sure enough, they all still worked as expected. I started going line by line to see if there was ANYTHING I could have missed. Nothing.
Then I noticed one difference; usually I used SVCUTIL to create my proxies and add them to my client application. This time, in the interest of keeping the demo "easy" I used the "Add service reference" option from Visual Studio. In all other ways it seemed to work, but I couldn't escape the fact that it was the ONLY difference between the two solutions.
I tried a few more things around the service reference. I regenerated the reference. Nothing. I thought that maybe it was somehow calling the service before the behavior was bound (I know, kind of crazy but after 90 minutes I was started to get a little desperate). So I started the host manually, waited till I was SURE that the behavior was bound, then started the client. Nothing.
So, having exhausted all other ideas, I dropped the VS created service reference and used SVCUTIL to create a proxy object and an application configuration file. I added them to my client project, fired up the service, made my service call and... it worked!
Not being totally familiar with how VS creates the service references, I can't say for sure why it doesn't work. But, given that the behavior works when called from client that creates the channel stack (either manually via a generated proxy), I'm guessing that the service reference option is building this channel stack in a different way or somehow circumventing the aspects of the runtime on the service side.
I've never deployed an application with VS generated service references, so I'm not sure how it works in production. Or if it's even possible to deploy a WCF client in such a way. Nor have I heard of anyone else doing it.
To be honest, I prefer SVCUTIL proxies or developer written invocations of the channel stack. It gives you more control over how your client interacts with the service and if something does go horribly wrong I can debug into the stack and see what's going on.
So Mr. "Add Service Reference..." I've given you a chance, but I think I'll stick with SVCUTIL.
See you all at CDoDN!
Print | posted on Thursday, May 15, 2008 10:52 AM