Having fun with code
  • Blog
  • Favorites
    • Favorite Books
    • Favorite Libraries
    • Favorite Tools
  • Utilities
    • SP 2010 Colors
  • Contact
  • Home /
  • .NET /
  • SharePoint 2010 Service Application Development 101 – Admin UI and PowerShell

SharePoint 2010 Service Application Development 101 – Admin UI and PowerShell

October 7, 2012 / Matt C. / .NET, SharePoint

In this post we explore how to configure various aspects of a SharePoint 2010 service application. This includes building some customizations in the application pages and extending the service application with powershell scripts. It is really up to your imagination when it comes to what you want to include and how you want to manage your service app, SharePoint gives you a tremendous amount of flexibility when it comes to these things.
This is part 4 of a short series on developing service applications in SharePoint 2010:

  • Part 1: Getting Started with SAF + Starter Solution (with Logging / Configuration / Service Locator)
  • Part 2: Custom Service Application – Logical Components
  • Part 3: Custom Service Application – Base Solution
  • Part 4 (This Post): Custom Service Application – Full Infrastructure (with Admin UI and PowerShell)
  • Part 5 (Final): Custom Service Application – Integrating features and capabilities into your service application (sample MailChimp integration)

Service applications in SharePoint have Properties pages. You have complete control over these. In this sample service application, I added the option for administrators to pick the endpoint protocol they would like to use in their service calls. This is also how you manually create the service application, where you specify the application pool to use (or create a new one), and also provide the server name and the name of the database(s) to use in support of your application (I like to setup my servers with aliases, so in the screenshot below: SharePointDB is actually pointing to a SQL Server instance, many consider this a best practice with SharePoint – 101 tip).

image

The same is done for the service application proxy. Just click on the MyCorp Service Application Proxy and click on Properties.

image

You’ll now be able to change various timeout settings and default settings for your WCF channel communication.

image

You can also manage your service application and it’s properties using PowerShell. I added some basic PowerShell commands to the project (download is provided at the end of this post) that will appear upon deployment in your SharePoint powershell console.

image

Publishing custom commands to your SharePoint PowerShell console is easy, but it’s time-consuming. You first write a cmdlet, like the following one:

using System.Collections.Generic;
using System.Management.Automation;
using System.Security;
using Microsoft.SharePoint.PowerShell;

namespace MyCorp.SP.ServiceApplication.PowerShell
{
    public sealed class GetMCServiceApplication : SPGetCmdletBase<mcserviceapplication>
    {
        private MCServiceApplicationPipeBind _pipeBind;

        protected override IEnumerable<mcserviceapplication> RetrieveDataObjects()
        {
            if (this.Identity != null)
            {
                base.DataObject = this.Identity.Read();
            }
            var list = new List<mcserviceapplication>();
            if (base.DataObject == null)
            {
                Log.Debug(LogCategory.ServiceApplication,
                          &quot;GetMCServiceApplication.RetrieveDataObjects: Identity not specified. Returning all applications&quot;);
                foreach (var application in MCServiceUtility.GetApplications())
                {
                    try
                    {
                        application.DemandAdministrationReadAccess();
                        list.Add(application);
                        continue;
                    }
                    catch (SecurityException)
                    {
                        Log.InfoFormat(LogCategory.ServiceApplication,
                                       &quot;GetMCServiceApplication.RetrieveDataObjects: User does not have access to MyCorp Service Application {0}&quot;,
                                       application.Name);
                        continue;
                    }
                }
                return list;
            }
            Log.Debug(LogCategory.ServiceApplication,
                      &quot;GetMCServiceApplication.RetrieveDataObjects: Returning the object specified by Identity&quot;);
            list.Add(base.DataObject);
            return list;
        }

        [Parameter(Mandatory = false, ValueFromPipeline = true, Position = 0)]
        public MCServiceApplicationPipeBind Identity
        {
            get { return this._pipeBind; }
            set { this._pipeBind = value; }
        }
    }
}

Then you register it in SharePoint using a SharePoint solution, with an xml file:

Get-MCServiceApplication
MyCorp.SP.ServiceApplication.PowerShell.GetMCServiceApplication
MyCorp.SP.ServiceApplication.PowerShell-help.xml

Set-MCServiceApplication
MyCorp.SP.ServiceApplication.PowerShell.SetMCServiceApplication
MyCorp.SP.ServiceApplication.PowerShell-help.xml

New-MCServiceApplication
MyCorp.SP.ServiceApplication.PowerShell.NewMCServiceApplication
MyCorp.SP.ServiceApplication.PowerShell-help.xml

And it’s a good practice to also include a help file so that users have all the info needed to know how to use the cmdlets you’ve written. The help file for the 3 cmdlets is also in the download.

In the last 4 posts, we created a complete service application infrastructure to integrate 3rd party systems and/or build custom enterprise applications within your SharePoint farm.

I’m going to hunt down a simple 3rd party system (something I haven’t played with yet) that I can showcase to give an example of how you can use this infrastructure in the way I describe. But if you’ve been following this series, I’m sure you already get the idea, but I think this will be a nice way to wrap up the series.

Thanks for reading.

[button link=”https://skydrive.live.com/redir?resid=30FD0C7F694C1B3F!293&authkey=!AJ9mKTemY0vGR_4″ color=”primary” target=”_blank” size=”large” title=”Code Download” icon_before=”download”]Code Download[/button]

Have fun! Use at your own risk 🙂

.net, admin, C#, mycorp, powershell, sharepoint

4 comments on “SharePoint 2010 Service Application Development 101 – Admin UI and PowerShell”

  1. Stone Mccray says:
    February 27, 2013 at 12:41 am

    You are describing nice information abut manually create the service application but if user do not have any application pool or how to create it.so that user can go ahead.

  2. Thomas Deutsch says:
    October 9, 2012 at 3:30 pm

    I watched the talk from Todd Bleeker today, searched for sample code – and i am on your blog again 🙂
    The ServiceStack for Sharepoint article was a great help – i used it with success. Thanks for that!

    I wanted to use xSockets.net as a SharePoint Service, but for now i have to take a step back to understand what to do to write a Service Application – and it will take some time to understand what is going on in your code.

    I only wanted to say: Thank you for the great work!

    • Matt C. says:
      October 9, 2012 at 6:00 pm

      Hey Thomas, glad the ServiceStack blog post helped. xSockets.net looks super cool, that specific project is new to me, I’m going to take a closer look at it. I downloaded their demo app and fired up a couple different browsers to see the real-time updates, very nice! Have fun with your service app project. I’m going to try to wrap this series up shortly and hopefully clear up any lose ends.

  3. Dew Drop – October 8, 2012 (#1,417) | Alvin Ashcraft's Morning Dew says:
    October 8, 2012 at 7:34 am

    […] SharePoint 2010 Service Application Development 101 – Admin UI and PowerShell (Matt Cowan) […]

Categories

  • .NET (20)
  • ASP.NET MVC (4)
  • JAMstack (2)
    • Headless CMS (2)
  • Miscellaneous (2)
  • Python (1)
  • REST (3)
  • SharePoint (8)
  • WordPress (1)

Tags

.net ado.net autofac binding C# chrome code generation command line console application csv dapper di entity framework integration ioc job scheduling engine json jsv learning llblgen load balancing micro-orm mycorp odata orm people editor people picker picker controls picker dialog plugins pmp python Quartz.NET rest saf service application servicestack sharepoint smo soap sql sqlalchemy tornado web server validation web api

Archives

  • May 2020 (2)
  • November 2013 (1)
  • June 2013 (1)
  • May 2013 (1)
  • March 2013 (1)
  • December 2012 (1)
  • November 2012 (1)
  • October 2012 (3)
  • September 2012 (2)
  • June 2012 (2)
  • May 2012 (1)
  • April 2012 (1)
  • February 2012 (2)
  • January 2012 (1)
  • December 2011 (2)
  • September 2011 (2)
(c) 2013 Having fun with code - "FunCoding" theme designed by mattjcowan using the Theme Blvd framework