Subscribe:
|
Categories:
ASP.NET
ast_mono
Asterisk
Code
FreeSWITCH
FSharp
Guatemala
Humour
IL
Korean
Mei
Misc
Misc. Technology
Personal
Photography
Security
Spammers
VoIP
Sign In
[Giagnocavo]Michael::Write()
Tuesday, December 02, 2008
Command line WCF Proxy Generation for Silverlight 2 RTM
I have a scenario where my web service app exposes several interfaces, and I want to use all of them from the Silverlight UI. The code generated by SvcUtil isn't completely compatible with Silverlight's WCF, meaning you need to do a lot of fixup 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 Silverlight has is "Microsoft.Silverlight.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 fixup 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 mutliple 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 ClientBase stuff, and the idiotic/useless "event based async pattern" code). Extra code just clutters up Intellisense, 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 fixup 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
Tuesday, December 02, 2008 7:56:09 PM UTC
Comments [1]
|
Trackback
Tracked by:
"Generate Silverlight 2 Proxy with SVCUtil.exe" (Developerslog.net)
[Trackback]
Tuesday, December 02, 2008 10:58:25 PM UTC
No joke. Add Service Reference is the WCF equivelant of drag-n-drop ASP.NET development. It's also SO bloated! It's like a DataGrid ViewState! Thus, I wrote my article (well, more like mini-book) at http://www.netfxharmonics.com/2008/11/Understanding-WCF-Services-in-Silverlight-2 to explain to people how to never EVER do that.
David Betz
|
dfbAT NOSPAMdavidbetz dot net
Name
E-mail
Home page
Remember Me
Comment (HTML not allowed)
Enter the code shown (prevents robots):
Live Comment Preview