Generating Proxies for Silverlight accessing a Silverlight-Enabled WCF Service
Generating Proxies |
I am writing this post because there just isn’t good information on generating your own proxies for Silverlight accessing a WCF Service. The problem is that svcutil.exe is the wrong tool. It will lead you to the front door of success but not let you into the building. The point is this, I wanted to understand how to connect to a WCF service without right-mouse clicking and choosing “Add Service Reference.” Why do it?
|
The real trick is to use SLSvcUtil.exe, not SvcUtil.exe. Did you know that? Depending on whether you want to generate for Windows Phone 7 or traditional Silverlight, here is where you can find the utilities:
|
The Silverlight-Enabled WCF Service we want to connect to |
Here is the project we are trying to connect to from the Silverlight project. Note that we do not want to “Add Service Reference.” |
Before connecting the Silverlight project to the Silverlight–enabled WCF Service, set some references |
Before actually generating the proxies and the configuration files, you need to first set some references as seen below. Notice we have System.Runtime.Serialization and System.ServiceModel. |
Start the Visual Studio Command Prompt as administrator |
The key step is upon us – to add the generated two files to the project. |
That’s it. That is the magic recipe that solved a couple hours of torture. |
Comments
Anonymous
December 12, 2010
Why not just use "Add Service Reference"?Anonymous
December 13, 2010
Hi Sandrino, A couple of reasons. First, I like knowing what "Add Service Reference" really does. It adds references to System.ServiceModel. It adds a proxy. It creates a configuration file. Second, I'd like to be able to re-use the output files in other projects without having to always add a service reference. Third, there's only two files to look at. If you add a service reference, a multitude of files are generated, which I think is very confusing. Finally, I had some errors with Windows Phone 7 clients that went away using the proxy.Anonymous
December 13, 2010
Thanks Bruno! It amazes me that people even question why you would want to do this.