Floating FB popout byF5debug

Getting Started with Windows Azure Media Services – Connecting to Azure Media Services Programmatically – #Meet Azure Edition

 

In this tutorial we are going to see how to programmatically connect to the Windows Azure Media Services using the Windows Azure Media Services SDK for .NET application development. In our earlier articles we have seen What is Windows Azure Media Services () and What are the steps to configure the Windows Azure Media Services Account (). Now in this tutorial we will write some code using the Visual Studio 2010 IDE and see how to connect to the Windows Azure Media Services and create a Cloud Context which is the key which holds all the necessary information of the entities that are used with the Azure Media Services from the application development perspective.        [more]

Open Visual Studio 2010 IDE and create a new Windows Application project or a WPF project with a valid project name, which be used in this series to explore the Windows Azure Media Services core features one by one as shown in the screen below.

clip_image002

Now let us design the page with some controls which basically required to connect to the Windows Azure Media Services using the CloudMediaContext class. The Server context provides the complete access to all the entities that are required to access the media objects like assets, files, jobs, tasks etc. Once we designed our screen it looks like below.

clip_image004

Next step is to add the Media Services reference, we can see the reference dll (Microsoft.WindowsAzure.MediaServices.Client.dll) available on the location of the SDK installed in the development environment i.e. C:\Program Files (x86)\Microsoft SDKs\Windows Azure Media Services\Services\v1.0 as shown in the screen below.

clip_image006

Next step is to add a APP.Config file where we are going to provide the Account Name and Account Key as the configuration which can be changed later based on the needs as shown in the screen below.

clip_image008

Now in the code behind declare a private variable and get the account name and the account key which can be used while creating an instance of the CloudMediaContext as shown in the code below. CloudMediaContext class provides the complete details of the entities that can be used in the application to manipulate the media object to its needs.

Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Configuration;
using Microsoft.WindowsAzure.MediaServices.Client;

namespace MeetAzureMediaServices
{
    public partial class MainWindow : Window
    {
        private static CloudMediaContext cmContext = null;
        private static readonly string strMsAccountName = ConfigurationManager.AppSettings["msAccountName"];
        private static readonly string strMsAccountKey = ConfigurationManager.AppSettings["msAccountKey"];

        public MainWindow()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            cmContext = GetContext();                     
        }

        static CloudMediaContext GetContext()
        {
            return new CloudMediaContext(strMsAccountName, strMsAccountKey);
        }
    }
}

clip_image010

Now we are done with the code, we can build and execute the project, we can see the application run successfully without any errors. We will not see any expected output as we are not catching any of the details to show as an output, but yes we have created a CloudMediaContext which has all the entities that can be utilized as per the requirement which we can see the list of entities available using the debugging mode as shown in the screen below.

clip_image012

So here in this tutorial we have seen how to programmatically connect to the Windows Azure Media Service and create a context holding the entities that are used to manipulate the required media objects as per the requirement. That’s it from this tutorial, see you all in the next blog of this series until then Happy Programming!!!

About Author: Karthikeyan Anbarasan, Microsoft MVP (Most Valuable Professional) in ASP.NET/IIS Architecture. He is the Founder and Chief Editor of the www.f5debug.net website and has authored books on Windows Phone and Business Intelligence(SSIS). He is also a Passionate Speaker and a Blogger on Microsoft Technologies.

You can Join Me On: Facebook, Twitter, Google Plus, LinkedIn

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

Recent Posts

Random Posts

Most Viewed

URL Shortner

Create your own short urls!!!

Site Counter

free counters

Disclaimer

This is a personal weblog. The opinions expressed here represent my own and not those of my employer. For accuracy and official reference refer to MSDN/ TechNet. I have documented my personal experience on this blog.

Protected by Copyscape Web Plagiarism Finder

Site Meter