SharePoint Dragons

Nikander & Margriet on SharePoint

Accessing a WCF service that is SharePoint context aware using the WCF channel factory

As discussed in forum thread http://social.technet.microsoft.com/Forums/en-US/sharepoint2010programming/thread/42f01511-3083-4d19-9058-00cf56af0fb7 , this is in fact an elegant way to reference a WCF service in the context of a given SharePoint web site without needing to change the web.config file of the SharePoint web application (this minimizing the overhead of managing custom software):

//Access WCF service Centre Detail Endpoint

WSHttpBinding binding = new WSHttpBinding();

EndpointAddress address = new EndpointAddress(SPContext.Current.Web.Url + “/_vti_bin/MyService/MyService.svc”);

ChannelFactory<IService> factory = new ChannelFactory<IService>(binding, address); IGetCentreNames client = factory.CreateChannel();

Leave a comment