I have been wrestling with SvcUtil all day, trying to get it to generate useful code for some IMS Enterprise Services (primarily Group Management Service, but there are others we need it to work for as well.) You can find the IMS service WSDL's here http://www.imsglobal.org/es/index.html.
I have come to the conclusion that SvcUtil is a useless afterthought from Microsoft that doesn't support the WSDL and XSD standards even in a half-assed way. It is incapable of generating a WCF service that conforms to the standard WSDL contracts that IMS uses AND functions at the same time. Despite generating compilable code from the following WSDL (http://www.imsglobal.org/services/gms/wsdl/imsGroupManServiceSync_v1p0.wsdl), observing the generated WSDL from the WCF service (?wsdl, ?wsdl=wsdl0, ?xsd=xsd0, etc.) shows that none of the operations exist, and onl开发者_开发知识库y a fraction of the types that were generated in code are actually recognized by WCF. If we screw with the generated code, we can get something that sort of functions (we are using SoapUI to test), but then it no longer conforms to the contract, so its useless to the people who really need to call these services.
Are there any alternatives to SvcUtil? (Please don't suggest the built in Visual Studio "Add Service Reference" tool, that is just as useless as it uses the exact same code as SvcUtil.) We need something that will give us a degree of control over how code is generated from the WSDL contract, what files each part ends up in, which namespaces each code element ends up in, etc. The IMS contract imports both XSD types specific to the services defined in the WSDL, as well as XSD types that are common to all IMS services. We need to be able to generate different assemblies for those types, and reference them in the generated code (similar to how SvcUtil is apparently supposed to do it...but it doesn't seem to do what it says its documentation says it does at all.)
I have been a huge fan of WCF until now. It obviously works when you use only .NET/WCF services, but any time you try to use it in a standards-compliant, cross-platform environment, everything goes to shit.
Have you had a look at the WCF Proxy Generator on Codeplex? Based on who's behind it (Kate Gregory and Michele Leroux Bustamante), there's hope it might be useful - plus you get the sources, so you can adapt / tweak at your heart's content!
(haven't had the time to take a serious look at it myself - yet - it's on the endless "To-Do when I get around to it" list....)
Plus check out this blog post here by Pedram Rezaei showing how to influence the Visual Studio "Add Service Reference" step with your own custom code.
Sorry that I don't have time in full to reply to this but there is an answer to your question. There is an interface that you can implement called IWsdlImportExtension which has two methods that you will be interested in. They are:
GenerateContract() and GenerateOperation()
If you implement these methods, you can actually control the way SvcUtil pumps out code by adding or removing CustomAttributes and so on. You need to compile a dll with the interface in it and then point the SvcUtil configuration at the DLL and the interface.
Using this method, you can can for example add Xml documentation to your outputted proxies and so on. There are some interested articles around about this.
精彩评论