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 Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: