System Center Orchestrator 2012 Beta: Using Web Service in .NET – Part 1 – Creating a SharePoint 2010 Web part

Download the sample solution here:

Download “SharePointRunBookOverview-v1.0.zip” SharePointRunBookOverview-v1.0.zip – Downloaded 207 times – 164 KB

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

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

By | 2011-08-09T12:00:00+00:00 August 9th, 2011|Automation|3 Comments

About the Author:

Jakob Gottlieb Svendsen

Twitter: @JakobGSvendsen

Jakob Gottlieb Svendsen is a Microsoft Cloud and Data Center Management MVP (http://mvp.microsoft.com/en-us/default.aspx), Working as Global Lead Developer, Senior Consultant and Trainer at CTGlobal, where he is one of the driving forces in keeping CTGlobal a System Center Gold Partner and member of the System Center Alliance.

Since he started at Coretech in 2007, he has focused on Scripting and Development, primarily developing tools, extensions and scripts for the System Center Suite. His main area is Automation (including OMS/Azure Automation, Service Management Automation, PowerShell and Orchestrator). Another area is Windows Azure Pack / Azure Stack, where he does implementation, development, workshops and presentations. He is a world-wide renowned voice in the Automation field.

He is passionately devoted to the community, to which he contributes by being a moderator at TechNet and sharing his knowledge at http://blog.ctglobalservices.com/jgs

  • Co-founder: PowerShell User Group Denmark
  • Speaker at MMS 2016, Minneapolis (www.mmsmoa.com)
  • SCU Europe 2014, 2015, 2016 (www.systemcenteruniverse.ch)
  • Microsoft TechEd North America 2014, Houston
  • NIC 2012,2013,2014,2015, Oslo (www.nic.com)
  • Microsoft CampusDays 2011, 2013, Copenhagen
  • Microsoft TechDays 2015, Sweden (www.techdays.se)
  • Microsoft Partner Event: New in SC2012 SP1
  • User group meetings (PSUG.DK , SCUG.DK/BE/NO, AZMUG + more)
  • Microsoft Certified Trainer.
  • Microsoft Scripting Guys Forum Moderator

Main working areas:

  • Automation (Azure Automation, SMA, SCO)
  • Windows Azure Pack / Azure Stack
  • System CenterVisual Studio Team Services / Team Foundation Server
  • Development:C#.Net, VB.NET, VBScript, PowerShell, Service Manager, OpsMgr, ConfigMgr
  • Orchestrator
  • Windows Azure Pack / Azure Stack

Training:

  • Azure Automation
  • Service Management Automation
  • System Center Orchestrator
  • PowerShell, VBScript, C#.Net, VB.Net
  • Windows Azure Pack / Azure Stack Development Workshops

3 Comments

  1. Dave Marcus November 2, 2011 at 15:21 - Reply

    Hi, thanks for this article. Where can we find details of the available methods and properties of the web service. eg. If we want to start a runbook, how do we do this. Also, if we want to check a running instance of a runbook to see its status, how do we do that?

    Thanks
    Dave

  2. anti aging skin care serums December 13, 2013 at 3:39 - Reply

    Hі, i feel that i saw you visited my weblog soo i came to return the desire?.I’m attempting tо
    in finding іssues to enhance my site!I assume its good
    enough to use a few of уour concepts!!

    My webpage – anti aging skin care serums

  3. como ganhar dinheiro December 13, 2013 at 22:10 - Reply

    Thank you a lot for sharing this with all of us you really
    understand what you’re talking approximately! Bookmarked.
    Please additionally consult with my site =). We could have a link alternate arrangement among us

    Also visit my web-site como ganhar dinheiro

Leave A Comment