Command line WCF Proxy Generation for Silver light 2 RTM

2:06 PM Abdulla Nabeel 0 Comments

I have a scenario where my web service app exposes several interfaces, and I want to use all of them from the Silver light UI. The code generated by SvcUtil isn't completely compatible with Silver light's WCF, meaning you need to do a lot of fix up to make it work in SL. Looking in the forums, I see mentions of "slsvcutil" and "slwsdl", but I've been unable to actually find these programs. The only thing that Silver light has is "Microsoft.Silver light.ServiceReference.dll", in the "Program Files\Microsoft SDKs\Silverlight\v2.0\Tools\ServiceReference" folder.
I opened that DLL up in ildasm, and it appears to just be some classes that work on a ServiceContractGenerator. Digging in deeper, yep, they just go through the generated CodeDOM and fix up stuff that isn't compatible. For instance, IExtensibleDataObject isn't supported. SL WCF also doesn't handle having Sync and Async methods (i.e, SomeOp and Begin/EndSomeOp) since they both have the same action. (You'll get an "An item with the same key has already been added" error.)
My main problems with the cutesy "Add Service Reference" UI are:
- I can't figure out how to tell it to use multiple WSDL files and share the data types.
- It generates a ton of files and VS gets all obsessive over them for some reason.
- It generates a lot of extra code (like the useless Client Base stuff, and the idiotic/useless "event based Async pattern" code). Extra code just clutters up Intelligence, so why bother?
[Add Service Reference is great for demos and perhaps simple one-offs... I can't imagine dealing with it for anything slightly complicated.]
So, I took the MSDN code sample for the ServiceContractGenerator, and hacked it up to do what I needed. Then I added the 2 lines to pass it through the Silverlight ServiceReference fix up thing, and presto - things look great. Usage is simple:
Usage: slsvchack <clr namespace> <outputfile> <wsdl1> .. <wsdlN>
The options are hard-coded to what I use and makes the most sense for Silverlight apps (in my opinion). I want to do a full fledged "SLSvcUtil.exe", but I think the right approach there is to dissassemble SvcUtil and patch in the Silverlight.ServiceReference stuff. But, I don't have the time right now.
Code: slsvchack.cs.txt (2.95 KB) [It's in C# 'cause the MSDN sample was, and my edits were minor. ]
Binary: slsvchack.exe (8.5 KB) [I'm too lazy to link in the Microsoft.Silverlight.ServiceReference.dll, so you'll need the Silverlight SDK installed.]

Code

You Might Also Like

0 comments: