共用方式為


Once again I am amazed

As stated earlier, I am working with some dynamically generated code at the moment. In order to cut short all the technicalities, I am working with proxies for webservices. One of the things that caused some raised eye brows with me was the fact that this generated code will have to generate types for all the types used by the web service (i.e. the public interface of the web service). These types will look like the types that you already have since you exposed them on the web service (assuming that you wrote the web service), but as far as the CLR is concerned, they are not the same types!

I was musing a bit on ways to elegantly solve this "polution" problem, when I got a subtle hint from a coworker. The solution lies in the SchemaImporterExtension class. Overriding the members of this class allows you to have more control over the code that is generated when you import a wsdl. All you need to do is to create some kind of mapping from the type (and namespace of your wsdl type) to a reference to a type in a given assembly and put that into the generation of the proxy code. It could not be much sweeter. Check out the samples on MSDN (https://msdn2.microsoft.com/en-us/library/system.xml.serialization.advanced.schemaimporterextension.aspx).

Again Windows Communication Foundation and the people that envisioned it have amazed me!