Tuesday, October 15, 2013

Connect application service to a web application programmatically

The following code will connect a custom user profile application service to a web application.
(SharePoint 2010)

           SPSite site = new SPSite("http://current site url");

           //Get all Service Proxies in the farm
           SPServiceProxyCollection farmServices = SPFarm.Local.ServiceProxies;

            // Iterate all the proxies
            foreach (SPServiceProxy service in farmServices)
                SPServiceApplicationProxyCollection serviceApplicationColl = service.ApplicationProxies;
                foreach (SPServiceApplicationProxy serviceApp in serviceApplicationColl.OfType<SPServiceApplicationProxy>())
                    if (serviceApp.DisplayName == "My Custom User Profile" && serviceApp.TypeName.ToLower().Contains("user profile service"))
                        //Add the service proxy to the web application
                         // update the application proxy group

                         //update the web application

No comments:

Post a Comment