Wednesday 21 September 2011

Generating Silverlight WCF Service Proxy

As a general rule it’s always best to stay away from the the Visual Studio Add Reference service proxy/client generator.

The preferred route is to use the utility tools provided, here’s an example of using the SlSvcUtil.exe tool:

cd "C:\Program Files (x86)\Microsoft SDKs\Silverlight\v5.0\Tools"
SlSvcUtil http://localhost:1558/Services/StocksService.svc /edb /ct:System.Collections.ObjectModel.ObservableCollection`1 /r:"C:\Program Files (x86)\Microsoft Silverlight\5.0.61118.0\System.Windows.dll"

ScreenShot131


Some points of interest:



  • You’ll only need to import the two generated files into your Silverlight client project.  When importing into my project I renamed the StocksService.cs to StocksServiceClient.cs
  • The command prompt doesn’t have to be the Visual Studio Command Prompt but does require elevated admin rights
  • /edb flag enables data binding (implements INotifyPropertyChanged)
  • /ct flag sets the collection type

For more info you can hit the MSDN docs:


http://msdn.microsoft.com/en-us/library/cc197958(v=vs.95).aspx

No comments:

Post a Comment