Download the sample solution here:

[download id=”53″]

This article is the first of my articles about using the Scorch 2012 Beta web service in .NET.

In this case I will show how a SharePoint 2010 Web Part that shows an overview of the works books.

This project is meant to be as simple as possible, making it easy to use as a starting point.

Later I will focus on other aspects of using the web service in .NET, please don’t hesitate to send suggestions.

This project will produce this result:

image

A non-formatted list of the Runbooks in the database.

System Center Orchestrator 2012 Web service is a WCF Web Service. You can read more about WCF Services here:

http://msdn.microsoft.com/en-us/library/cc668772.aspx

Creating the Web Part

1. Creating SharePoint Project

  • Start Visual Studio 2010
  • Expand “Visual C#”. “SharePoint” and “2010”
  • Select “Visual Web Part”

image

  • Type in the SharePoint URL in the wizard.
  • Now you have and empty Visual Web part project ready.

2. Generating Custom Class from the web service

To be able to use the web service in .net, you will have to create a class file, containing the format and content of what the web service has to offer.

This is done by using a console application in .NET framework 3.5 called “DataSvcUtil”

  • Open a commandprompt
  • Run this command. The command creates a .CS file in the format of the web service.

“%windir%\Microsoft.NET\Framework\v3.5\DataSvcUtil.exe” /dataservicecollection /version:2.0 /language:CSharp /out:ScorchEntities.cs /uri:http://ctscorch.coretech.intra:81/Orchestrator.svc

image

  • Copy or move the file to the project folder

image

  • Add the file to the project (remember to enable “show all files” )

image

3. Adding controls

  • Open “VisualWebPart1UserControl.ascx” in the designer
  • Open toolbox and drag a “GridView” from the “Data” category to the designer

image

4. Adding references and custom code

  • Right click “References” in solution Explorer and click “Add Reference..”

image

  • Add “System.ServiceModel” from the .NET Tab. Click OK.

image

  • Repeat the procedure, adding the “System.Data.Services.Client” component.

image

  • Repeat the procedure, adding the “WindowsBase” component.

image

  • Now you are ready to write the code!
  • Right click the designer and click “View Code”

image

  • Add the following code to the “Page_Load” method in the code file for “VisualWebPart1UserControl.ascx
        protected void Page_Load(object sender, EventArgs e)
        {

            var ScorchSVC = new Microsoft.SystemCenter.Orchestrator.WebService.OrchestratorContext(new Uri("http://ctscorch.coretech.intra:81/Orchestrator.svc"));
            ScorchSVC.Credentials = System.Net.CredentialCache.DefaultCredentials;

            GridView1.DataSource = ScorchSVC.Runbooks;
            GridView1.DataBind();

        }

First line creates the Orchestrator Web Service Object, this object will by default connect as anonymous.

this is not allowed by default on the web service. Therefore we add the Default Credentials, this will make the part connect to the service as the current user that is logged on to SharePoint. This could be changed to another user / service user, if needed.

Then we get all the Runbooks from the Scorch Object. Experiment with and explore this object, to make it show other data than a runbook overview.

5. Editing Web Part Info Details for SharePoint

  • Double click “VisualWebPart1.webpart” file in solution explorer

image

  • Edit the “Title” and “Description” parts of the XML File.

image

  • That’s all !

6. Testing and Inserting the web part

  • Press F5 to start the solution in debugging mode.
  • First time it will ask you for your SharePoint URL.
  • Click “Site Actions” and “Edit Page”

image

  • Click “Insert” in the “Editing Tools” part of the ribbon
  • Click “Web Part”

image

  • Select the “custom” category and your web part should appear here

image

  • Select the web part and click “Add”
  • Now, your web part should be shown in the page.

image