Building a SharePoint Service Application to Provide Auto-completion Services for AJAX-enabled Rich User Controls – Part 2

Part One – The Service Application
Part Two – The Service Application’s Admin Interface
Part Three – The WCF Service Endpoint
Part Four – The User Application Page

Browse Complete Source Code
Download Visual Studio 2010 Solution

Update 10/29/09: Added Powershell cmdlets to create, retrieve and update properties of the demo service application.  Refer to the accompanying sample project for details.

Part Two – The Service Application’s Admin Interface

The Create and Manage Application Pages

In the project, I’ll add a SharePoint Mapped Folder to the [14 Hive]\TEMPLATE\ADMIN directory.

In Solution Explorer, I’m going to expand the newly created ADMIN mapped folder, right-click the AutocompletionDemo subfolder, and from the context menu Add > New Item. I select a SharePoint Application Page and name it ServiceCreate.aspx. Then, I repeat the process to add one more page named ServiceManage.aspx.

The ServiceCreate page will be a popup dialog box, and as such should be modified to inherit from SharePoint’s ~/_layouts/dialog.master master page. This page will implement place holders for its master page’s PlaceHolderDialogHeaderPageTitle , PlaceHolderDialogDescription and PlaceHolderDialogBodyMainSection content sections. Refer to the accompanying sample project for the complete listing.

Inside the PlaceHolderDialogBodyMainSection, I add the necessary controls to gather user input before creating the service application. This page will ask for the service application’s name, application pool identity, and a check box to set this instance as the default.

Inside the ServiceCreate page’s code-behind, within the CreateNewServiceApp method is where the new Auto Completion service application is actually created. All of the heavy lifting for creating the service application resides with a SPLongOperation. Refer to the accompanying sample project for the complete listing.

The ServiceManage page is where developer’s are free to add any user configurable settings for the service application. The Auto Completion service application has no user configurable options, so this page is largely left blank for the purposes of our demo. Note that this page’s master page is ~/_admin/admin.master.

At this point, the Auto Completion service application can actually be deployed to SharePoint, and instances of the service application can be provisioned in Central Administration. Of course, the application doesn’t actually do anything yet, but the core infrastructure pieces have been defined. To verify this, right-click on the AutocompleteDemo project in Solution Explorer and select Deploy. The solution will deployed, and after a few seconds, you should see a "Deploy succeeded" message in the bottom left corner of Visual Studio.

To verify deployment, I can open SharePoint’s Central Administration site and click on Manage service applications under the Application Management menu heading.

Selecting any item in the list of services will cause the Service Applications ribbon to appear. I’ll click the New button to see the Auto Complete Service Application list there. Now I can go ahead and click it to create a new service application instance.

If all is well, I’m presented with a dialog box to create a new Auto Completion service application instance.

Congratulations! If everything works on this next step, most of the hard part is over. I can go ahead and complete the form by entering an instance name and selecting an application identity. When finished, I click OK to provision the service application. If the provisioning succeeded, a pair of listings for the new service application and its proxy should now be available on the Manage Service Applications Page. I haven’t added any user configuration options for this demonstration, but clicking the listing’s link to will visit the ServiceManage page.

One more step to verify the provisioning was successful is to check that the service application’s virtual application was created in IIS. To do so, I can open Internet Information Services (IIS) Manager from Administration Tools on the Start menu of the Windows Server running SharePoint 2010. Next, I’ll expand the Sites node and then expand the SharePoint Web Services node below that. I right click on one of the virtual applications below SharePoint Web Services and select Switch to Content View.

I’m looking through the list of virtual applications which have guids for names. Notice SharePoint’s built-in service applications such as MetadataWebService.svc and WebAnalyticsService.svc. I’m looking for the virtual application with a guid for a name that that contains our Service Host file YouCompleteMeService.svc. If everything checks out, the empty WCF service has been provisioned.

Next:
Part Three – The WCF Service Endpoint