Category: wcf

Developing Custom Screens for SharePoint 2010

When building a SharePoint site, you may find yourself having to build custom screens. This may be because you need to integrate with a third party system, or perhaps your users require a more sophisticated user interface than can be provided out of the box.

There are a few (non exhaustive) options around building custom screens in SharePoint 2010, and I have created them on the basis that you need to read and write to some tables held in a separate SQL Server instance.

There is no conclusion to the best method. You should always consider your business requirements in determining which is most appropriate.

This is also assuming that you have to use SharePoint as a platform instead of ASP.NET.  (At least for Options 1 & 2)

Option 1: Custom .NET WebPart + Services

For total flexibility, you can create a custom web part with any kind of experience you like.  You can employ AJAX, Javascript and third party UI components such as Infragistics or Telerik.

The seperate service layer allows you to abstract your data access code away from your User Interface. The additional benefit is that your service layer can take advantage of .NET 4.

Advantages

  • Implement any user interface you like
  • Abstract data access / business logic away from user interface
  • Easier to secure (no database connections in web site web.config)
  • Easier to unit test web services
  • Leverage .NET 4 in your service layer

Disadvantages

  • Requires more coding for extra layer

Option 2: Custom .NET Webpart + Direct Access

This is the same as Option 1, with the Service Layer removed.

Advantages

  • Implement any user interface you like
  • Faster to develop.

Disadvantages

  • Restricted to .NET 3.5
  • Database connection strings in SharePoint web.config
  • Harder to unit test User Interfaces than abstract services.

Option 3: JavaScript + SharePoint REST Services

SharePoint 2010 can now expose all of its lists through a REST API. This combined with External Data Sources make SharePoint a good web service provider.

The idea is that the whole User Interface can be built with JavaScript ( and JQuery ), that can easily consume and update data through the SharePoint REST API.

The JavaScript is hosted in a content web part, although a Visual Web Part may give you more flexibility for this.

Advantages

  • No .NET coding required, just JavaScript / JQuery
  • Easy to configure SharePoint to do this
  • For a large number of end users, this approach will be far less demanding on the SharePoint server. (All User Interface processed on the client machine).

Disadvantages

  • All User Interface is managed on the Web Browser
  • Permissions to read / update / delete data are manages far down in the database
  • Harder to build event driven logic in JavaScript than ASP.NET
  • All JavaScript can be read by the end user. Hacking may be possible.

Option 4: InfoPath

SharePoint 2010 can host InfoPath forms inside the browser. This combined with External Data Sources means you can very quickly create a user experience on top of external data.

Advantages

  • No .NET coding required, just define InfoPath forms
  • InfoPath rules are easier/safer to implement than .NET business logic
  • Easy to configure SharePoint to do this
  • Ideal for simple operations such as filling a table with data.

Disadvantages

  • Little control over the User Interface and the controls you want to use (few custom development options)

Using external source data for SharePoint lists

 

Aim of this walk-through: Use data held in a database as a value list in SharePoint.

SharePoint 2010 can use external data as lists. In this example I’m accessing a table of Airport data held in SQL Server, since I felt that 10,000 entries is not something you want to typically maintain in a SharePoint list.

SharePoint alllows you to connect to external data sources from a .NET assembly, SQL Server directly or WCF.

I prefer to use WCF, since I’m not convinced that many scenarios would want SharePoint having direct access to the database. In addition, .NET code would be best managed by a WCF service anyhow.
Using SharePoint Designer, I define a new External Content Type called ‘Airports’:
Under External Content Type Operations, click on the hyperlink (“Click here to discover…“)
On the following screen, click the “Add a new connection” button.
In the following dialog, enter the URL of your WCF endpoints.
You will then see all the web methods listed. By right-mouse clicking on each you will be able to assign various operations to them. At the moment we are just interested in ‘Read Item Operation‘ and ‘Read List Operations‘.
In my case:
  1. GetAirport returns a specific airport (Read Item Operation)
  2. GetAirports returns all airports (Read List Operation)
GetAirport and GetAirports are simple. Go through their respective wizards and assign the parameter ‘code’.
After you have completed the operations, click ‘Save’.
On the External Content Types, you will be able to right mouse click and define an External List on Airports.
Give it a name, and click OK. We are now ready? Unfortunately not quite yet! If you try and view your new list, you will see that you get a message “Access denied by Business Data Connectivity“.
Go to: ( This would be too many screen shots, and I’m sure you can work this out)
Central Administration -> Application Management -> Manage Service Applications -> Business Data Connectivity Services

Click on your list (which should now appear here) and in the following screen click ‘Set Object Permissions’.
You can now add groups of users to use this data connection. In this quick example I’ll just assign Administrator in the first instance.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
TIP: Once this is applied, it will take some time to become active in SharePoint. You can force it to apply right away by going to:
Central Administration -> Application Management -> Manage Services on Server-> Business Data Connectivity Services
Stop this service, and then Start again.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
If you then browse to your new external list:
All done!
Now we have a list with.. 10,000 items! The next post will look at how we make this more usable.

Pictures in the Cloud – SSDS demo app

I’ve been playing around with SQL Server Data Services, Microsoft’s new concept for the ‘datacenter in the cloud’.

Anyhow, I’ve been having a bit of hack around to show how pictures can be stored by this kind of service. There isn’t any reason to use this over the other online photo sharing sites, but it demonstrates how to use the API.

http://www.codeplex.com/CloudPictures

As far as I can tell, there are no ‘best practices’ about how to use SSDS (probably because no one is publicly using it for the enterprise yet). Hopefully writing this application will show me the best way to achieve this.

There isn’t a ‘release’ yet, but if you download the source, build it (VS 2008) get a username and password and edit the app.config then it should work straight away.

WCF on the Compact Framework

Playing with the Visual Studio 2008 beta last year, I was disappointed that the WCF service binding did not work out of the box with the Compact Framework. (The generated classes can not be used by the Compact Framework subset)

Luckily the Compact Framework 3.5 Powertools has introduced a command line utility called NetCFSvcUtil.exe (equivalent to the standard WCF SvcUtil.exe tool).

Andrew Arnott has a good blog post describing what it can and cannot do.

MSDN has a good tutorial as well.

I hope to write more about this in future posts

Microsoft Managed Services Engine

I’m trying to work out why the Microsoft Managed Services Engine project isn’t getting more attention.

The short answer (I guess) is that the concept is pretty dry unless you are an architect who has encountered these sorts of problems 🙂

It is a great tool for virtualizing your web services. One previous project I worked on had an internal IT cost of around $40,000 to open a new port in their firewall for a new version of their client. This is an issue that MSE would have solved easily.

Versioning

MSE allows you to host multiple services with the same names on a single endpoint.

It uses the format of the request to decide which version of the web service is appropriate for which service.

Retiring

When you decide that you do not want to maintain an older service, you can deactivate it from the managment console.

Furthermore, you can redirect requests to the retired service to another by providing an XSLT transformation.

Policies

I admit that I don’t fully understand the capability of this feature. I know you can apply a ‘policy’ to a service such as running a RegEx expression against its output. There is also a policy to ‘throttle’ a WCF service, which could be useful if you want to give priority to the newer one. It seems to be straightforward to define new policies.. I can think of some security policies that might work well.

Reading around, it seems this was actually developed by Microsoft for some customers and they decided to release as an open source CTP project.

The team do not seem to have a blog or anything around this, so it is hard to know where it is going. Nevertheless, I hope it gets a formal roadmap soon since this is something I’d like to consider using on customer projects.

Some questions I have that I will endeavor to answer myself over the coming weeks:

  1. Do virtualized services perform as well as ‘real’ ones?
  2. Are there ‘best practice’ guidelines?
  3. How can load balancing be applied?

Visual Studio 2008 Project Compatibility

UPDATE: 16th December: I felt it fair to update the post with my findings

++++++++++++++++++++++++++++++++++++++++++ 

At my company we have a great DSL based tool for generating WCF Services.

However, because of various reasons, the tool will only run under Visual Studio 2005 and not the all new and great Visual Studio 2008.

That is a pity, because I wanted to show off a new concept and hence wanted to use the WPF designer in 2008 to make an impression for the client.

Well, I’m I thought I was in luck! Apparently I can use the same projects in VS 2005 in VS 2008 and vice versa.

http://blogs.msdn.com/djpark/archive/2007/11/07/how-to-use-solutions-and-projects-between-visual-studio-2005-and-2008.aspx

So you don’t have to abandon VS 2005 to try out the new features in VS 2008 in your projects… this is good stuff Microsoft!

I should have read the article more closely: I opened up my VS 2005 C# library project in VS 2008.. and it gave me an upgrade wizard 😦

Luckially I was able to use my assemblies from VS 2008 with no trouble, but it could have been so much better.