Tuesday, November 24, 2009

SharePoint 2010: Business Connectivity Service Part I

At this point there is still a lot of confusion surrounding the name of the new Business Data Catalog. In SharePoint 2007 it was Business Data Catalog in 2010 it’s Business Data Catalog or Business Connectivity Services or External Content Types. In Visual Studio 2010 it’s still Business Data Catalog and in SharePoint Designer 2010 it’s called External Content Types, but what’s in a name? I’ll call them Business Connectivity Services.

In SharePoint 2007, the BDC lacked any form of UI, but in 2010 that has changed! You can find the Business Connectivity Services under: Central Administration –> Manage Service Applications –> Business Data Catalog. My preferred weapon of choice is Visual Studio, but if you want to do the basics then you can use SharePoint Designer (it’s a lot friendlier). When you’re trying to integrate with a very basic WCF service or SQL database or even a .dll (!!) SharePoint Designer is the way to go. For all your other services (or custom work) use Visual Studio.

For this first part I would like to do a basic thing. Staying close to the old BDC way. The BDC works with a Finder and a Specific Finder method. The Finder method returns a list of arbitrary items and the Specific Finder returns an item based on the ID of that item. I also want to do some custom work, so I won’t be creating my own webservice that has those two (Finder, Specific Finder) methods, that would be too easy.

I found a webservice at: http://www.webservicex.net/country.asmx that returns a string, but the string is an XML DataSet representation of a list of countries. If you try to set this thing up with the old BDC you’ll only get one object with a string in it. In the new BCS you now have the ability to customize the Finder and Specific Finder methods.

First you have to install the Microsoft Visual Studio 2010 tools for SharePoint 2010. Start Visual Studio 2010 and create a new Business Data Catalog model from the SharePoint 2010 projects.

VSTS BDC

The Business Data Catalog Model starts with a basic model with Entity1 and an Entity1Service. If you run this project and create an external list in SharePoint, you’ll see your first BDC application running in SharePoint.

Visual Studio now has a great new designer for the BDC Model and it’s a good one. Another good thing is, is that everything is XML. You can edit the DataCatalog files in the XML editor, I don’t recommend it, but you can. Stay in the BDC Explorer for now, it has everything we need to do. Go to the Solution Explorer and we’ll start by renaming the Entity1 to Country and remove all of the properties of it. Add three new properties to Country: IsoCode, Name and Currency. Add a Web Service Reference to the project for http://www.webservicex.net/country.asmx. Go back to the BDC Explorer and open BusinessDataCatalog1. You will see that there is still an Entity1 in there, rename it to Country. Rename Identifier1 to IsoCode and rename the methods to FindAllCountries and FindCountryByIsoCode (Finder and Specific Finder). I found a bug in this release; whenever you rename a method in the BDC designer it automatically creates a new method in your service. I hope they’ll fix this in the Beta1.

In the BDC Method Details you’ll see all the details of all the methods. You’ll find that there will still be references to Entity1 or Identifier1. You can change these to Country and IsoCode respectively. One thing you should realize is that you’re now creating a model on top of the Country and CountryService classes. Make sure that all the names and objects in your model have underlying C# properties and classes. If you select the FindCountriesByIsoCode method in the BDC Explorer, you can open the combobox for Country (or Entity1 if you forgot to rename it) next to returnParameter and click on Edit. You’ll jump to the BDC Explorer and see the Model version of Country. Make sure that all the properties of Country are in the Model version, with the right name and type name. You can add “Properties” by right clicking on Country and select “Add type descriptor”.

When you’re done, your BDC Model should look something like this:

BDC details

If you’ve done all of this correctly you can go to the CountryService.cs (in the Solution Explorer) and start coding on the FindAllCountries and FindCountryByIsoCode methods. When you’re all done do not forget to copy your serviceModel settings (app.config) to the SharePoint web.config file. (The automatic deployment in Visual Studio works great, but it forgets configuration settings). If you’ve done all of this correctly, then simply press F5 and navigate to your external content list and you’ll see this:

countrylist in sharepoint

Wednesday, February 18, 2009

Workflow 3.5 Designer Rehosting

Since the release of Workflow, Designer Rehosting has been promoted as one of the good qualities of Workflow. In each article or presentation Designer Rehosting keeps coming back as a good thing. So I decided to put it to the test. I started with trying to find a reason why a customer would want to use Designer Rehosting. Microsoft gave me the following reasons:

  • (Design Time) To view, create or modify Workflows
  • (Runtime) To view the current state of an executing workflow by utilizing the tracking information.

Both reasons are obvious and still don't give me any reason to sell it to a customer, they can use Visual Studio to do exactly the same. There's another reason why your customer might want to use Designer Rehosting. Maybe in some sort of specific scenario he wants to customize views to his needs or choices. With Designer Rehosting you can choose to expose as much or as little functionality of Workflow as you wish.

I started with catching up on Designer Rehosting, MSDN has some great articles on that, you can find them here. Microsoft made some sample bits to get you up to speed, those can be found here. After I read the documentation (that's a lie) and grinding the code, I tried to do it myself. I must admit, I expected it to be easier. The actual hosting WF in a Winforms app is easy, but to put something of a framework together that was hard. Maybe I should have just copied all the code from the sample bits, but I hate to do that.

All the things you need to get your view in order can be found in System.ComponentModel.Design. I used the WorflowView, DesignSurface and the WorkflowDesignerLoader to get my View in order. After a little bit of yelling and screaming at my PC, the view looked like this:

winapp

The thing that got me screaming was the toolbox control, I expected that this toolbox would be in System.ComponentModel.Design, it was not. I did not find a control that showed me all the Activities from System.Workflow.Activities, so I ended up making the thing by myself. I don't know why Microsoft chose to not expose that control, but it sure would have helped me. Then again I'm now able to (for example) let the InvokeWebServiceActivity disappear from my toolbox, or show one of my own custom Activities.

So now I'm able to drag and drop my Activities to my Workflow, that's cool! This is the basics on Designer Rehosting. I can load a Workflow and show it in my app. I didn't have time to get the Tracking ready, that will be my next project and just for fun I want to be able to add some code, but that's a whole different ballgame.

To be honest I think that you should really think about if you want to use Designer Rehosting. It sounds easy and they make it look like you really want to, but you need to write a lot of plumbing code before you even have a simple app like this. I don't think there will be a lot of customers that really need Designer Rehosting, there are usually other (better and simpler) solutions for the same problem.

Thursday, October 30, 2008

VS2010 and Architecture

I had a little time left and started playing around with Visual Studio 2010 and I noticed some cool features. There's a new project type called the Modeling Project. I was a bit sceptical about this, because the modeling in VS2005 and VS2008 was not the experience I expected...

In VS2010 it is now possible to create Use Case diagram, Activity diagram, Component diagram, Sequence diagram and Layer diagram. Even versioning is possible with your favorite source control product. (TFS). Now I must have been asleep for a while or busy doing other things, but Microsoft has joined OMG, so the new UML diagrams are al UML 2.4! Now this I hadn't expected.

It's also possible to create Sequence diagrams from existing code, which is a big help if you're a new architect on a existing project. Talking about acrhitectional discovery VS2010 adds a new Architecture Explorer which creates Sequence diagrams, project dependency graphs and all sorts of handy diagrams, which can help you understanding the system.

From my point of view the Architecture Explorer is the best! It's a cool new tool in VS2010, which helps me get a better understanding of the system I'm working with. I can't wait to use it in real projects.

.NET Services and The Service Bus

The Service Bus is a new messaging infrastructure part of the new Windows Azure Services. It addresses a few Connectivity challenges we all are aware of:

  • IPv4 Address Shortage
    • Dynamic IP address allocation
    • Network address translation
  • Firewalls layered over firewalls over firewalls

So how does the service bus address these problems? There are a couple of components the service bus consist of:

- Naming: Because of the practical constraints of DNS (High update propagation latency, DNS names hosts and not instances etc.) the service bus naming system works in a different way i'm not going to dive into it now, but a few features are: R/W access with Access Control through the Service Bus Registry, Updates are reflected instantaneously and it names endpoints, not machines.

- Service Registry: The service registry is registry for service endpoints, not a general purpose directory. The registry is layered over the naming system and the services should publish themselves in the registry. The registry also provides the family of bindings for the service bus. Right now the service bus can be used with the following bindings:

  • BasicHttpBinding
  • WebHttp
  • WSHttp
  • WS2007Http
  • WSHttpContext
  • WS2007Httpfederationg
  • NetTcp
  • NetTcpContextBinding

So how does the service bus works with these bindings? If you use NetOnewayRelaybinding then the Receiver creates an outbound connect bidirectional socket and register in the cloud (Registry of the Service Bus) (TCP/SSL 828 outbound open required) The sender outbound connect one-way net.tcp (tcp/ssl 808/828) to the Service Bus. The sender sends a message the Service Bus creates a route to the receiver.

The NetEventRelayBinding allows muliple receivers, so you can send a message and both/more receivers will receive the message.

NetTcpRelayBinding / Relayed is the one you should almost always use, because it got the highest throughput. A connection starts just like NetOneWay, but instead of connecting to the Service Bus we connect to the load-balanced front-end nodes. These nodes are some sort of Socket-Socket Forwarders the nodes sends a control message to the cloud and the cloud sends a control message to the receiver. The receiver then connects to the socket-socket forwarder and then the receiver and sender are connected through the socket-socket-forwarder.

The last part I haven't discussed is security, this is where the Relay Access Control Model comes in.

- Relay Access Control Model:

RECEIVER MODEL: The receiver goes to the acces control service (azure) and acquire access token and asked for a claim for listen permissions on the service bus relay. Then this access token with subscription is passed to the service bus relay. The service bus relay will evaluate that token.

SENDER MODEL: The same way: get a token send it to the relay, relay evaluate, and now the relay will pass the normal message to the receiver.

There's even a possibility for you if you don't want to use the Access Control Service just add the following line in your BindingConfig <security relayClientAuthenticationType="None"/>. I don't think it's a good idea, but you can.

Wednesday, October 29, 2008

"Huron" Sync enabled cloud data hub

To my surprise the Microsoft Sync Framework team has teamed up with the SQL Services Lab to produce "Huron".

"Huron" is a combination of SQL Data Services and Sync Framework. Which actually means that an arbritary database can be published to the SQL Data Services (which is a part of the Windows Azure Services) and after that Sync Framework kicks in.

For example: You have some sort of SQL Database which contains information that you want to share with your colleagues (on mobile devices for example). It's fairly easy to publish this database to the "cloud" (SQL Data Services). The Data Service will store your database as a blob in the cloud. After you've uploaded your database, sync framework does a first sync of the data in the database. Another user can subscribe to your database, this means that a template of the database is downloaded to their local drive and sync framework does a first sync of al the data. This user also get a range of primairy keys he can use for adding rows. Which means that a user can add a row and the primairy key of that row will not be the id of the last row + 1, but will be the first number in the primairy key range. This little trick is done to reduce the sync logic. (Two users adding a row which gets the same id, sync framework can't determine which row is should be persisted in the real database).

Everyone who have been working with Sync Framework won't see anything new here accept the fact that the database is now out in the "cloud" and not in the company. So actually nothing new here, just a hype to sell Live Services. I understand that for smaller companies which don't have the money to provide the cost of administration, deployment and availability this could be a good solution. For bigger companies who already have the network and the maintenance departments (and the budget) for supporting these kinds of technologies, this can be an option if you want your data up in the "cloud", but I think there are better options.

First contact with Oslo

The first presentation about the language Oslo was by Don Box and David Langworty. It was really good to see that I don't have to know T-SQL anymore!

Why "M"

  • We want creating and interacting with oslo content to be simple and natural
    • Having a box-and-line design experience is an important enabler
    • Having a complementary textual experience is equally important
  • M is how we achieve the latter

What is "M"

  • "M" is a language for defining domain models and textual domain-specific languages (DSLs)
  • M domain models define schema and query over structured data
    • Values, constraints, and views
    • Natural projection to SQL
  • M DSLS define projections from Unicode text to structured data
    • Rule-based transformation
    • Grammar driven text editor integration

What "M" is not

  • An object-oriented language
    • No polymorphism, virtual dispatch
    • "ls-a" determined based on structural subtyping, not stipulation
  • A data access technology
    • M domain models compile down to T-SQL
    • Tool chain supports course-grained loading/unloading of schemas and values - not an OLTP solution
  • A replacement for T-SQL
    • Far less expansive feature set
    • Tool chain supports linking/invoking T-SQ

So Oslo is an abstraction on T-SQL and although it is not finished yet, it is already fun to play with. A little example:

First to start with a normal table:

Module Contacts

{

People

{

{ Name="persona", Age=29 },

{ Name="personb", Age=28 }

}

}

This actually means that we defined a schema and filled the table with two rows.

Next up constraints:

Module Contacts

{

-- Constraints:

People :

{

Name : Text where value.Count <= 30;

Age : Integer32;

}*;

People

{

{ Name="persona", Age=29 },

{ Name="personb", Age=28 }

}

}

What you see here is a constraint on the People table, which in T-SQL would look like this:

Create table [Contacts].[People]

{

[Age] int not null,

[Name] nvarchar(28) not null

}

It's still another language to learn, but I like this more then T-SQL.

Tuesday, October 28, 2008

WPF on Windows 7

Scrott Guthrie just presented some new features in WPF on Windows 7. They added some more interesting controls like a jumplist. A jumplist add some contextual support for your app. So when you right-click on your app in the taskbar, it shows the jumplist with it's available actions. They also improved the theme support and Deep Zoom will be in the WPF 4.0!

They enabled multitouch, which you can use to make Surface-like applications (if you got the hardware!)

Just to prove they believe in WPF (How could they not) they even built Visual Studio 2010 on WPF! This means that it's going to be really easy to extend Visual Studio specially on the visualisation part.

Today there will be a new WPF toolkit out, with a new datagrid (finally), datepicker, calender, ribbon and a preview of the Visual State Manger available in WPF in .NET 4.0. The Visual State Manager introduces two concepts: State transitions and visual states. A control, such as a datepicker, has multiple visual states that define how the datepicker should look like when the mouse is hovering over it, or when it is pressed etc. Transitions are used to define how visuals dynamically change as the control moves from one state into another.

The new WPF Toolkit will be available here.