Consuming Windows Azure DataMarket with SharePoint 2010 via Business Connectivity Services

Windows Azure MarketPlace DataMarket is a service that provides a single consistent marketplace and delivery channel for high quality information as cloud services. It provides high quality Statistical and Research data across many business domains from financial to Health Care.. You can read more about it here

How do we consume this content in an enterprise scenario? In this post we are going to look at how to integrate Azure Marketplace Datamarket with SharePoint 2010 via Business Connectivity Services via .NET Connector as a external list. This enable us to surface Azure DataMarket data through SharePoint 2010 lists which opens up world of possibilities including going offline with SharePoint workspace and participation with workflows, enterprise search etc..

Let’s first start with Azure Datamarket. Logon to https://datamarket.azure.com with your live id and subscribe to a dataset that that you are interested in. I selected European Greenhouse Gas Emissions DataSet. Also note down your account key in the Account Keys tab as we will need this information later on.

Untitled1

The Dataset details give you the input parameters and results as follows.

Untitled

You can navigate to the Data set link with your browser and view the oData feed. We are going to consume this oData feed with WCF Data Services. This allows us to use Linq to filter the data.

LinqPad is a nifty tool to develop and test LINQ Query Expressions. It allows you to connect to Windows Azure DataMarket Datasets and develop the queries against the data as shown below.

clip_image006

Now lets move on to VS2010 and create a BCS Model project as shown below.

 

image

Rename the Default Entity in the BDC Model designer and set the properties that you want to expose as the external content type

image

Once all properties are set DBC Explorer displays my model as shown below.

image

Now our BDC model is ready. Now lets implement ReadList and ReadItem BDC operations.

First Add a Service Reference to your project. Set the Address to the location of your Azure DataMarket

Dataset and Discover the oData Feed as shown below.

image

After the service reference is added , we can implement the ReadItem method as shown below.

 

image

Note that Service Reference Context requires your live ID and account Id pass as credentials in to the service call.

image

Once all operations are implemented Click F5 to build and Deploy your BDC model  into SharePoint. Once deployed

log on to Central Administration and go to Manage Service Applications and select Business Connectivity Services

and view the Details of EmissionStat Content Type being Deployed. You might wanted to permissions for this content

type at this point.

image

Now the external content type is defined all we need is a external List based on this content type. Fire up SharePoint

Designer and Create an external list referencing the new External content type just created

image

Once the list is created navigate to the list in the portal. Note that Windows Azure market place Data Market content

now surfaced through SharePoint 2010 list as shown below. The VS2010 solution associated with this post can be download here

image

Viewing item details shows full item details using our ReadItem BCS operation.

image

Integrating Structured data (Azure) with Unstructured content (Collaborative Data) in SharePoint allows you  to create high business valued

composites for informed decision making purposes at all levels in your organisations. Happy Cloud Collaboration!


Leverage and Extend Claims based identity in SharePoint 2010

Windows Identity Foundation (WIF) is the platform on which SharePoint 2010 claims authentication is based. WIF, which is fully supported in SharePoint 2010, ADFS 2.0, ASP.NET, Windows Communication Foundation (WCF), and any other .NET application you care to develop, provides the infrastructure necessary to generate, transmit, and process claims-based identity in a simple and straightforward manner. It removes the roadblocks imposed by legacy authentication schemes like NTLM and Kerberos and puts control directly into the hands of developers, users, and IT security professionals. long story short, it’s a framework written to help solve identity issues common in the of cloud computing and service-oriented architecture.

The idea of claims based identity is one that many people are willing to try. Getting accurate information out there to the public though does take time.

The important point is this is based on industry standards.  Many different entities are on board along with Microsoft in this matter. The digital world continues to give us new opportunities and those involved believe that this will help all of us to get the most out of it. There is a strong foundation in place to continue building upon. The use of AD FS v2, CardSpace, and Windows Identity Foundation are all important pieces of this puzzle.

As a demonstration of these capabilities, I’ll show how SharePoint 2010, WCF,and WIF can be put together to solve the identity delegation problem. In this demo session part 1 I start establishing the trust relationship between ADFS 2.0 and SharePoint with PowerShell and demonstrate how the claims get into SharePoint.Then we build and deploy a claims viewer Webpart with WIF programming model. In part 2 We start with a web service that is front-ending line-of-business information stored in a SQL database. Then, we’ll configure it to use WIF to request the calling user’s claims from SharePoint and process the token so that authorization decisions can be made. we’ll surface this information in SharePoint 2010 as an External Content Type using Business Connectivity Services (BCS).

This session was presented in SharePoint Saturday Melbourne 2010  in Oct 2010  and MOSSIG user group Nov 2010.

images

Click here to view a recorded screencast of this session. 

The slide deck of this session is shared here

The SharePoint Claims Viewer Visual WebPart VS2010 solution,  Claims based WCF Service VS2010 solution and necesssary powershell scripts to add and remove identity provider in SharePoint 2010 can be downloaded from here.
 
I encourage you to look at following links for further information about this topic

Building an interactive dashboard with SharePoint 2010 RESTful Services

REST (or Representational State Transfer) is an easy way to easily get or post items to a server-side web service.  It is used in situations where you would use a web service but do not want the overhead and tightly-coupled nature of SOAP.   Technically, REST is not a protocol, but an architectural style. It complies to Open Data Protocol (OData), a Web protocol for querying and updating data that provides a way to unlock your data and free it from silos that exist in applications today.

SharePoint 2010, being based on WCF in the .NET 3.5 Framework, has built-in RESTful web services which allow us to take advantage of this simplicity in custom applications we write..

The RESTful service can be accessed via  http://<site collection url>_vti_bin/ListData.svc

This blog post is based on my Demo #2 last week at MOSSIG user group meeting in Melbourne.

 

uuo

 

The Data for this dashboard is sourced from 2 custom lists “Products” and “Sales”  The two lists has parent-child relationship.

aas

 

Sales List

aas2

Edit Sale Item.

aas5

 

Any given list can be accessed via the RESTFul service. This demo application is using  WCF Data Services to read/write to sharepoint  list Data, then, WCF Data Services  was the first Microsoft technology to support the Open Data Protocol. It provides developers with client libraries for .NET, Silverlight, AJAX etc..

image

Once the service proxy is created from ListData.svc you will have typed access to all the list data with LINQ support.  The following code segment in the ViewModel  shows how sales data is obtained from the service along with corresponding product details and register for Unit of Work tracking when property change.

 

private void GetSalesData() { // Set up the data context if it hasn't been done already if (_dataContext ==null) { _dataContext = new HomeDataContext( new Uri("http://spdemo/_vti_bin/ListData.svc")); } Sales = new ObservableCollection<SalesItem>(); //Prepare REST service request var query = (from s in _dataContext.Sales.Expand("ProductCode") select s ) as DataServiceQuery<SalesItem>; query.BeginExecute( (ar) => { IEnumerable<SalesItem> _salesItems = query.EndExecute(ar); foreach (SalesItem item in _salesItems) { item.PropertyChanged += ((sender, e) => { var entity = (SalesItem)sender; //track changes to entities _dataContext.UpdateObject(entity); }); Sales.Add(item); } NotifyPropertyChanged("LineValue"); }, null) ; }

The viewModel implements INotifyPropertyChanged event for the purpose of Notifying the view of Data changes and visa versa. The ViewModel exposes two properties LineValue (bound to the slider) and ObservableCollection of SalesItems. These 2 properties are declaratively bound to both chart types (bar and pie). I am using few charting controls  from Silverlight Toolkit (http://silverlight.codeplex.com/)  with XAML Declarative bindings as shown below.  

 

            <TextBlock x:Name="ScoreTextBlock" Text="{Binding LineValue}" />
            <chart:Chart Height="200" LegendTitle="Item" Title="No of Units Sold By Product" 
                         x:Name="MyBarChart" Width="562" DataContext="{Binding}">
            <chart:ColumnSeries x:Name="MySalesChartData" Title="Sales of Products" 
                    ItemsSource="{Binding Sales}"
                    IndependentValueBinding="{Binding ProductCode.ProductName}"
                    DependentValueBinding="{Binding NoofUnits}"/>
            </chart:Chart>
            <chart:Chart Height="230" Title="Sales Distribution" x:Name="MyPieChart" Width="562" Margin="4,0">
                <chart:PieSeries ItemsSource="{Binding Sales}" 
                    IndependentValueBinding="{Binding ProductCode.ProductName}"
                    DependentValueBinding="{Binding NoofUnits}" Background="#FF2B1515" />
            </chart:Chart>

The VS2010  solution that contains source code for this demo is uploaded here.

Enjoy!


Handling WCF FaultExceptions with SilverLight 3

Silverlight 3 Introduced the capability of handling WCF fault exceptions.

Using FaultContracts is a good way of managing and shielding WCF exceptions, but I also wanted the silverlight client to be able to:

  • Catch generic CLR exceptions and propagate them to the client as a generic fault exceptions.
  • Catch some application specific exceptions and propagate these to the client as a general fault so that I can build the logic around the client to escalate the the cause that raised the exception in runtime.
  • Log any unhandled exceptions that may sneak there way up to the services.

Whenever sensitive data is involved create a fault exception and pass the error data to the client sufficient enough to build the logic around the client to handle the fault senario

WCF provides great exception shielding by default, but we wanted a bit more control. This is where WCF IErrorHandler interface allows you to intercept any faults or exceptions before they are sent back to the client. To use this properly, you still need to define your FaultContract as required for expected exceptions.

However By default, WCF services return fault messages with an HTTP 500 response code. Due to limitations in the browser networking stack, the bodies of these messages are inaccessible within Silverlight 3 , and consequently the fault messages cannot be read by the client.

To send faults to a Silverlight client that are accessible to it, an WCF service must modify the way it sends its fault messages. The key change needed is for WCF to return fault messages with an HTTP 200 response code instead of the HTTP 500 response code. This change enables Silverlight to read the body of the message and also enables WCF clients of the same service to continue working using their normal fault-handling procedures.

The modification on the server can be made by defining a WCF endpoint behavior for Silverlight faults. Then this behavior can be enforced either by service contract declarative style or via configuration. More details about this can be found here

The attached sample Silverlight project shows how message behaviour extensions,Fault contracts and IErrorHandler interfaced is used to achieve the above requirement.