Monday, 10 December 2007

VS2005 Service Reference Wizard

I've posted a couple of times (here and here) about building WCF proxies through pre-build events. The Add Service Reference function in Visual Studio is handy for this but has some limitations (read about them in the previous posts). Generally speaking, though, the Add Service Reference function does exactly what you need, at least to get yourself up and running and your program speaking to a service.

But there's an issue. I call it a bug. And it is mighty annoying. It has wasted two afternoons of my time already. Once when I first came across it and a second time when a colleague, three weeks later, had the same problem and I could not remember what I'd done to fix the issue. Now I'm writing it down once and for all.

Using the Add Service Reference tool, if you add a URL pointing to a service's WSDL the tool will appear to find the service, but the actual generation of the proxies will fail. Why? Because the address of the WSDL is not technically the address of the service. Bloody hell - you'd think they could have fixed that issue, wouldn't you?

So make sure you remove the ?wsdl from your service reference URL.

If you're having other issues with the Add Service Reference tool that sound like there's a Content Type issue, it's likely that some of the references in your WSDL are not accessible to svcutil.exe. You can check this by adding ?xsd=xsd0 to the service reference URL (in a browser). If you get a 404 Not Found message it's likely that the account used to host your service (the one associated with the service's application pool) does not have read access to the Windows temp directory. This doesn't seem to be documented anywhere, and I found the solution on Erwyn van der Meer's blog.

No comments: