Skip navigation
SharePoint on a Cloudy Day

SharePoint on a Cloudy Day

Integrating Azure with SharePoint 2010

When you think about the cloud and SharePoint, a number of things may come to mind. For example, SharePoint Online—Microsoft’s hosted cloud offering for SharePoint. This is a cost-efficient alternative for organizations that don’t want to run and manage their own instance of SharePoint on-premises. Perhaps Web 2.0 might come to mind. SharePoint is a platform, and there is a growing amount of web-based services and applications, social or otherwise, that can be integrated with SharePoint in different ways. A third thing that might come to mind is tying Azure services and applications into SharePoint. Although each of these integrations of cloud and SharePoint are interesting, the focus of this article is on the latter integration: Azure and SharePoint.

Windows Azure is Microsoft’s OS in the cloud, and it provides reach, scalability, and reusability for both hardware and software. There are several Azure offerings: Windows Azure (core management and storage features), SQL Azure (data management), and Azure AppFabric (helps developers connect services and applications in the cloud). Azure provides a set of tools and SDK for your cloud-based development, plus it enables you to develop and deploy solutions into the cloud. This, in essence, makes the web your potential audience and allows you to scale resource usage in a more optimized way. You pay for what you use as opposed to having servers sitting on racks running at less-than-full capacity.

For SharePoint, Azure represents a significant opportunity to integrate cloud-based innovation into both your on-premises and hosted instances of SharePoint 2010. But to be clear, at present we’re talking about integration at the consumptive level and not integration at the foundational level. Put another way, you aren’t hosting SharePoint on Azure; rather, you’re integrating Azure applications and services with SharePoint. However, this integrated marriage can be very powerful, enabling you to launch rich, cloud-based services across multiple SharePoint instances (and indeed versions). Azure is the future of cloud computing for Microsoft, and with SharePoint as a leading web-based collaborative platform, the opportunity is ripe for building compelling significant bridges across these two technologies.

 Points of Convergence

There are a number of different ways to integrate SharePoint and Azure, which cut across shallow integrations (such as using IFRAME to integrate ASP.NET applications hosted in Azure) to more service-centric integrations (such as creating and deploying a custom service to Azure and then integrating with a SharePoint list or Web Part). What is good about this spectrum is that as a developer, you can choose to build and deploy packaged SharePoint solutions (e.g., WSPs that have a ready-made Azure integration) or create the service and guidance on how to consume the service.

Approaching this from a SharePoint perspective, the table in Figure 1 provides a summary of some of the more common places where you can integrate Azure with SharePoint 2010. There are a number of different ways to integrate with SharePoint (and indeed Office as well). To illustrate how you can accomplish this integration, I’ll show you a simple example.

 

 Integrating a Custom Azure Service with SharePoint

You can get the full walk-through of this example along with code and other Azure and SharePoint integration discussion at http://blogs.msdn.com/steve_fox. The specific walkthrough that provides in-depth coverage of the example in this article can be found here: http://blogs.msdn.com/b/steve_fox/archive/2010/06/15/integrating-a-custom-azure-service-with-business-connectivity-services.aspx

Your Development Environment. When integrating SharePoint and Azure, you’ll need to have an Azure developer account and a developer environment set up. To get an Azure development account, go to http://www.microsoft.com/windowsazure to get started. Here you can find information about getting the developer key and download information for the Visual Studio tools and Azure SDK, which you need when developing for Azure.

Next, you’ll need to ensure your development environment includes the following:

  • SharePoint
    • Windows 2008, 2008 R2
    • SharePoint 2010
    • Office Professional Plus
    • Visual Studio 2010
    • SharePoint Designer 2010
  • OR
    • Download the Information Worker VM from the Microsoft download center
  • Azure
    • Developer Account/Keys
    • Azure SDK & App Fabric SDK
    • Azure tools for Visual Studio 2010
    • SQL Server 2008 R2 Express
  • Optional
    • Silverlight tools for Visual Studio 2010
    • Silverlight 4 runtime

 

Building the Custom Azure Service. After you have your development environment set up, you’re going to want to first develop and deploy your Azure application. An easy way to get started is to develop a “self-contained” Windows Communication Foundation (WCF) service that you host in Azure; it’s self-contained because it will have no external dependencies (such as entity data models). You create the WCF service by using the Visual Studio 2010 Azure tooling and creating a new Cloud Service application and selecting the WCF Worker Role.

This example leverages an object called Customer with the following properties:



    public class Customer


    \\{


        public string tempCustID \\{ get; set; \\}


        public string tempCustTitle \\{ get; set; \\}


        public string tempCustFirstName \\{ get; set; \\}


        public string tempCustLastName \\{ get; set; \\}


        public string tempCustEmail \\{ get; set; \\}


        public string tempCustPhone \\{ get; set; \\}


    \\}


 

The core WCF service functionality provides two publicly accessible web methods and a helper function. The two web methods enable you to get a single customer record (getACustomer()) or get all of the customer records (getAllCustomers()). To get a single record, you pass an int parameter that corresponds to a Customer ID. For example, the following code snippet shows the web method call to getACustomer() and the return of a populated array object (which is populated using variable assignments and a LINQ query).



public string\\[\\] getACustomer(int custID)


        \\{


            generateCustomerData();


 


            string strCustID = custID.ToString();


            string\\[\\] returnCustomer = new string\\[6\\];


 


            var returnListOfData = (from customer in myCustomerList


                                    where customer.tempCustID == strCustID


                                    select customer).ToArray();


 


            foreach (var cust in returnListOfData)


            \\{


                returnCustomer\\[0\\] = cust.tempCustID;


                returnCustomer\\[1\\] = cust.tempCustTitle;


                returnCustomer\\[2\\] = cust.tempCustFirstName;


                returnCustomer\\[3\\] = cust.tempCustLastName;


                returnCustomer\\[4\\] = cust.tempCustEmail;


                returnCustomer\\[5\\] = cust.tempCustPhone;


            \\};


 


            return returnCustomer;


        \\}


 

 

Critical to these two web methods is the helper function (generateCustomerData()), which dynamically creates a set of customer records at run-time. This data construct is thus in-memory and simply creates and assigns property values and then adds the object to a list collection (myCustomerList). To follow is an example of the object instantiation, property assignment and addition of the new object to the list collection.



Customer cust1 = new Customer();


cust1.tempCustTitle = "Dr.";


cust1.tempCustID = "1";


cust1.tempCustFirstName = "Jane";


cust1.tempCustLastName = "Doe";


cust1.tempCustEmail = "[email protected]";


cust1.tempCustPhone = "425-332-1092";


myCustomerList.Add(cust1);



 

When you’re done building the WCF service, you build and deploy to your Azure instance. You can right-click and select Publish to accomplish this tasks, and Visual Studio will invoke your Azure developer portal and open the correct Publish folder containing two key files: an archive file (service package file) that has all of your project assemblies, and a configuration file (cloud service configuration) that contains an XML configuration file that is required by Azure. You can find these files in the \bin\Publish folder. You click Upgrade or Deploy in Azure and then Run to deploy the new service, in which case you will be prompted to browse for and add the service package file and cloud service configuration file to your Azure site. Note that you can also suspend or configure the XML file directly from your Azure developer portal. When the service is deployed, Ready will be displayed with a check-mark indicator. You can now navigate to the service URL (e.g. http://contosowcfservice.cloud.net/Service1.svc) and consume this service within SharePoint.

 Integrating the Custom Azure Service with SharePoint. With the service deployed to Azure, you can now integrate that Azure service with SharePoint (or with any other application that supports service integration). One way to integrate the service would be using the new Business Connectivity Services (BCS). This enables you to either integrate the service into SharePoint using SharePoint Designer 2010 or use the BDC Metadata Model template in Visual Studio 2010. If you choose the latter, because you have two main read methods in the service (getACustomer() and getAllCustomers()), you can easily map these web methods to the two pre-requisite methods for the BDC Metadata Model template (and indeed the two methods you need for any external list in SharePoint 2010—an external list is a list connected to an external data system with CRUD capabilities and is the evolution of the BDC Web part in SharePoint 2007).

For example, if you were to create a new project using the BDC Metadata Model template in Visual Studio 2010, you would need to ensure you do four things:

  1. Ensure the custom object (by default Entity1) reflects the same properties as the Customer object you created earlier;
  2. Amend the ReadItem() method to consume the getACustomer() web method;
  3. Amend the ReadList() method to consume the getAllCustomers() web method; and
  4. Ensure the BDC Explorer has all of the correct TypeDescriptors in place.

If you were to amend the ReadItem() method, the following would look similar to the code you might use to surface a specific entity when consuming the getACustomer() method.



    public static Entity1 ReadItem(string id)


        \\{


            myAzureSvc.Service1Client myWCFProxy = new myAzureSvc.Service1Client();


            string\\[\\] returnedData = new string\\[6\\];


            returnedData = myWCFProxy.getACustomer(Int32.Parse(id)).ToArray();


 


            Entity1 entity1 = new Entity1();


            entity1.Identifier1 = returnedData\\[0\\];


            entity1.tempCustTitle = returnedData\\[1\\];


            entity1.tempCustFirstName = returnedData\\[2\\];


            entity1.tempCustLastName = returnedData\\[3\\];


            entity1.tempCustEmail = returnedData\\[4\\];


            entity1.tempCustPhone = returnedData\\[5\\];


 


            myWCFProxy.Close();


 


            return entity1;


        \\}


 

Similarly, when you amend the code in the ReadList() method, your new code might look like the following:


…  


public static List<Entity1> ReadList()


        \\{


            myAzureSvc.Service1Client myWCFProxy = new myAzureSvc.Service1Client();


            var salesData = myWCFProxy.getAllCustomers();


 


            List<Entity1> mySalesInfoList = new List<Entity1>();


 


            foreach (var item in salesData)


            \\{


                Entity1 tempEntity = new Entity1();


                tempEntity.Identifier1 = item.tempCustID;


                tempEntity.tempCustTitle = item.tempCustTitle;


                tempEntity.tempCustFirstName = item.tempCustFirstName;


                tempEntity.tempCustLastName = item.tempCustLastName;


                tempEntity.tempCustEmail = item.tempCustEmail;


                tempEntity.tempCustPhone = item.tempCustPhone;


                mySalesInfoList.Add(tempEntity);


            \\}


 


            myWCFProxy.Close();


 


            return mySalesInfoList;


        \\}


In both cases, you can see the WCF service being implemented and then consumed within the context of your BDC Metadata Model project.

When you’re done amending the code in the ReadItem() and ReadList() methods, you deploy to SharePoint by right-clicking the project and selecting Deploy. You can then use the new external content type (which is the output of the project) to create a new external list. This list calls the Azure service at runtime, then, at two times. The first time is when it loads the list (it calls the ReadList() method which subsequently calls the getAllCustomers() web method). The second is when you click on a particular item to view a specific list item (it calls the ReadItem() method which subsequently calls the getACustomer() web method).

Leverage Azure to Create Applications for SharePoint

This article introduces some of the ways in which you can integrate SharePoint 2010 and Azure. This integration is from an application (or consumptive) perspective as opposed to building and hosting SharePoint on Azure. That said, there are some very powerful ways to integrate SharePoint and Azure. Further, SharePoint provides native support for service and data integration. For example, you can manage SQL Azure credentials using the Secure Store Service, and the BDC Metadata Model provides native support for cloud-based service consumption for external lists.

This article also provided a high-level discussion of a specific example of Azure and SharePoint integration. Specifically, it discussed a WCF service that was deployed to Azure and then integrated and consumed with SharePoint using BCS—a new set of services to SharePoint 2010 that facilitate external data and system integration with SharePoint.

You can build many different interesting and compelling integrations with SharePoint, and leveraging Azure certainly expands your opportunities as a developer and as a company trying to create applications for SharePoint.

 Getting Started with Azure and SharePoint

To find out more about how you can get started, check out the following resources:

Windows Azure Portal: www.windows.azure.com

Azure Channel 9 Learning Center: http://channel9.msdn.com/learn/courses/Azure/

SharePoint Channel 9 Learning Center: http://channel9.msdn.com/learn/courses/SharePoint2010Developer/

MSDN SharePoint Developer  Center: http://msdn.microsoft.com/en-us/sharepoint/default.aspx

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish