Tuesday, 20 May 2008

I hadn’t touched the topic of web service proxy generation for a long time, but in order to fine tune our new message contract generation framework for Genome, I had to check it out once more.

My concrete problem is very simple: I want to generate a proxy for a web service, but instead of generating some DTO types based on the wsdl, I would like to use my DTO classes that are already implemented (I know that the wsdl-generated ones are just fine, but mine are a little bit better).

The old solution was to let Visual Studio generate the proxy code, and remove the shared type from it. And hope that you don’t have to update it too often, because you will have to do this again. It seems that with the web service proxy there are no real improvements. Although wsdl.exe has some nice settings, like /sharetypes, you cannot invoke it from the “Add Web Reference” dialog. So you have to complicate the development workflow anyway. I wonder why MS did not implement a backdoor, by which I could provide additional wsdl.exe parameters…

The better news is that the WCF client generator can also generate clients for web services. And in the “Add Service Reference” dialog, you can even configure it to reuse types from existing assemblies, if they are referenced in the client project. Super! This is what I wanted. But it does not work :-( … At least not if the service is an ASMX web service (it seems to work fine for WCF services). It still generates my DTO classes.

I have played a lot with it. It seems that the problem is that it does not recognize the matching DTO class, because it is annotated with XML serializer attributes ([XmlType], etc.) and not with WCF attributes. Indeed, if I attribute the class with [DataContract] and [DataMember] attributes, it finds it! However, there is a checking mechanism in the client generator that can check whether the reused type matches the wsdl definition. And it is this that seems to fail, even if I apply exactly the same attributes as it would generate. I have looked around, and it seems that this checking mechanism might fail even for WCF classes.

This is a trap. There is a validation framework that provides false validation errors and cannot even be switched off. So I’m still exactly where I was 5 years ago: manually removing the generated types from reference.cs.

Posted by Gáspár

Genome | WCF