Forward Visibilty - Code Blog

Saturday, September 5, 2009

Silverlight - Automated Deployment - use WCF with relative Path

This is a great trick. Stop using the config file automatically generated in for WCF client in Silverlight and just use a relative path. This makes it so you don't need different config files for each environment and open up that XAP file. In the code below the UIService is just the class that is generated by adding a service reference to WCF in silverlight. So easy, super useful.

void PageConstructor()
{
UIService.UIServiceClient myService=GetUIService();
myServices.Completed.... += CompletedEvent(....);
}

void PageLoad(....)
{
myService.Async...();
}

public static UIService.UIServiceClient GetUIService()
{
var uri = new Uri(Application.Current.Host.Source, "../SLServices/UIService.svc");
return new UIService.UIServiceClient("CustomBinding_IUIService", uri.AbsoluteUri);
}


Also read WCF is Singleton if you want to understand why I put this code in the constructor.

No comments:

Post a Comment