I did it so you don’t have to: Connecting to Dynamics CRM Online from BizTalk Server

If you’re a consultant like me, you’ve probably got similar calls from some key account manager, as I did yesterday:

KAM: Hi Mikael. I’m just about to close this super big deal, with this super important Customer.
Me: Really! Good for you.
KAM: Yeah, we’re really close. But to rap it up, I was wondering if you could help me out a bit
Me: Sure. What do you have in mind?
KAM: Could you come with me to meeting with the customer on Monday? (this happens on Thursday 6PM)
Me (getting suspicious): mmmWhat do you want me to do?
KAM: A demo!
Me: Demo of what?
KAM: The customer want us to show how to integrate Dynamics CRM Online with SAP using BizTalk.
Me: What?
KAM: Yes, yes. The customer wants us to show it live! You know, they want to see you do it
Me: ARE YOU HIGH? (I didn’t actually say that, but I was thinking it)
Me: It will not happen! I haven't worked with SAP since 3-4 year ago. I’ve never worked with CRM Online (or off-line for that matter). I’m fully booked tomorrow, and I want to spend the weekend with my family as X-mas is coming up.
KAM: But we need to close this deal
Me: NO!
KAM: Please
Me: No way!
(Yada, yada, yada)
Me: Ok, I’ll give it a try (I’M SUCH AN IDIOT!!!!!)

So here it is: How to connect to Dynamics CRM Online from BizTalk Server

To begin with, if you want to integrate with CRM Online, you have two options. Either use an un-typed web-service API or use a tool called CrmSvcUtil.exe to create a proxy class for you. Each of these comes with some challenges and limitations:

Using an un-typed web service, can of course be somewhat messy, but the SDK provides you with the schemas you need (more on that later). The biggest challenge, however, is to authenticate to the service as it assumes you’re using Windows Live Id. Authenticating against the service would require an additional four calls to the service to finally get the authentication tokens needed to create the security header. An then figure out a way to to add the headers in a pipeline. The steps needed are described by Girish Raja here.

The proxy created using the CrmSvcUtil is quite nice, since it’s typed, but of course I can’t use it in a send port. I would  have to make the call using the inline-send approach from within an expression shape in an orchestration. And thereby loose the built in re-send functionality and more, that ships with BizTalk.

As none of these approaches was acceptable, I begun looking for other alternatives. What I really wanted was an authentication behavior, that I could add to my WCF-Custom send port adapter. 

Building the Custom WCF Behavior

What I needed was a Message Inspector that would build up the security header as Girish Raja did in his sample, and then add that header to the SOAP envelope. This class is called LiveIdAuthenticationMessageInspector and inherits from IClientMessageInspector. This gives two methods to my class: BeforeSendRequest and AfterReceiveReply.

public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, 
    System.ServiceModel.IClientChannel channel)
{
    string securityHeader = HeaderHelper.GetSecurityHeader(this._username, this._password, this._crmUri);
            
    request.Headers.Add(MessageHeader.CreateHeader("Security",
        WSSecurityUsernameTokenProfileNamespace,
        string.Empty,
        new SecurityHeaderSerializer(securityHeader),true));

    return null;
}

In the BeforeSendRequest method is where I can add the security header to the message before the message is sent out. The the BeforeSendRequest method I call a helper class returning the actual header. The GetSecurityHeader method is going through four steps to build up the header:

  1. Get Windows Live Device Credentials
  2. Register Device Credentials and get binaryDAToken
  3. Get Security Token by sending WLID username, password and device binaryDAToken
  4. Build up the security header with the token from previous step.

(This sample does not cache the tokens! I strongly suggest you add some caching logic before you run this in production)

After the header is created it is added to the request, using a custom serializer, as it would otherwise be HTML encoded.

public void AfterReceiveReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
{
    Trace.WriteLine("[bLogical] LiveIdAuthenticationMessageInspector:AfterReceiveReply called");
    int index = reply.Headers.FindHeader("Security", WSSecurityUsernameTokenProfileNamespace);
    reply.Headers.RemoveAt(index);
}

When BizTalk (or any other WCF client) receives the response it will throw an exception, as it doesn’t understand the Security header. I might have gone away with adding the http:http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd schema to BizTalk, but as I don’t need it, I just removed it from the header on the way back.

Part from the Message Inspector, I also added an EndpointBehavior and a BehaviorExtensionElement. The LiveIdAuthenticationBehaviorExtensionElement needs to be registered in the configuration using the behavior in BizTalk

After you have registered the behavior, you can focus on the normal BizTalk tasks like building orchestrations and mappings. To get started with consuming the CRM Services, have a look at Richards post. The only thing I’d like to emphasis is that the correct schemas are part of the SDK (sdk\schemas). After you run the Consume WCF Service Wizard, remove all schemas and replace them with the the once in the SDK. Better yet, put all those schemas in a separate schema project, and reference that project from other projects where you’re using them.

1. Add the behavior to the Global Assembly Cache

Open up the LiveIdAuthentication project, build and add it to the global assembly cache.

2. Register the behavior in the configuration

(sorry about the formatting).

<extensions>
  <behaviorExtensions>
    <add name="liveIdAuthentication" type="LiveIdAuthentication.LiveIdAuthenticationBehaviorExtensionElement, LiveIdAuthentication, Version=1.0.0.0, Culture=neutral, PublicKeyToken=698ceec8cebc73ae"/>
  </behaviorExtensions>
</extensions>

You can do this either in a config file (machine.config or BTSNTSvc[64].exe.config) or in BizTalk (WCF-Custom Send handler):

I prefer the later as I would otherwise need to make the changes to all the servers in the group. Just copy the extension element above, into a config file, and import the file from the Transport Properties dialog above. Or you can point to the app.config file in the sample.

3. Add the Endpoint Behavior

Open the send port and click the Configure button to open the WCF Transport Porperties. Select the Behavior tab and right-click the Endpoint behavior node, and select Add extension. Select the liveAuthentication extensions. Select the extension and set the properties.

 

You’re done.

Use this code as you like, and on your own risk. If you make improvements, I’d appreciate if you notify me. One thing I know could be done better, would be to cache the tokens and re-use them for the next call.

 

Download the Dynamics CRM LiveId Authentication Behavior sample here.

HTH

Blog Post by: wmmihaa

BizTalk Solution Analyser

For a while I’ve been working on an idea and whitepaper around analyzing source code to measure the size and complexity. There are some tools around which can do this but my differentiator is that I was interested in BizTalk projects and wanted to look at how these could be measured. Note however this can be easily used for non-BizTalk projects too.

The aim is to be able to understand the size and complexity of a solution and to allow some real metrics to contribute to your understanding of the Total Cost of Ownership of your solution. Using the tools I have developed alongside this I have been working with some customers to integrate the analysis into the build and continuous integration processes so that we can produce a report of the code and also track changes over time to monitor how the code based vary in terms of size and complexity.

The whitepaper goes into the detail of the theory about how we measure code and is available on the following link:

https://skydrive.live.com/redir.aspx?cid=983a58358c675769&resid=983A58358C675769!1820&parid=983A58358C675769!1819

The source code and application/tools which can do this for you are available on the following codeplex project site

http://biztalksolutionanaly.codeplex.com/

At this stage the project is being used to monitor approximately 20 code bases at two companies who have significant investments in BizTalk and I’m also looking for feedback from the community over other things we should measure.

It would be great to hear how you get on with this or if you have any views on it.

Artigo “BizTalk Server – Princípios Básicos dos Mapas” na Revista “Programar”

Artigo “BizTalk Server – Princípios Básicos dos Mapas” na Revista “Programar”

For the BizTalk Portuguese Community, I publish an article call “BizTalk Server – Basics principles of Maps” on the Magazine “Programar” and soon I will translate to English. J%u00e1 est%u00e1 dispon%u00edvel a 32%u00aa edi%u00e7%u00e3o da Revista PROGRAMAR, uma publica%u00e7%u00e3o digital gratuita com diversos artigos relacionados com desenvolvimento de software. Esta edi%u00e7%u00e3o cont%u00e9m um artigo da […]
Blog Post by: Sandro Pereira

BizTalk is Dead? Long Live BizTalk!

The BizTalk Server team blog sneaked out an announcement yesterday that you might have missed. I caught it due to an RSS feed. BizTalk Server 2010 R2 is coming. Now the question is when, and a better question will they change the name, as they should to BizTalk 2011?

We have a while to wait, no firm dates yet, but since it adds support for Windows Server 8 and SQL Server 2010 (codename Denali) which don’t have announced release dates yet either, that isn’t too much of a surprise. They are saying about six months after those products release. Support for Visual Studio 11 was also part of the announcement.

It doesn’t sound at all earth shattering, more just a bit of a jiggle. It may calm some of the fears as they are frequently bandied about from the title of the article, that BizTalk is a dying breed. Rest assured that QuickLearn will be on the forefront of training for this new product as soon as a beta is available.

In addition to support for the new platforms another point of interest is a change to licensing making it possible to provide BizTalk as a hosted service , and to transfer a license to a hosting provider. This is obviously a step in moving BizTalk into the cloud, a change that has long been planned. We’ll have to see what that means as to whether Microsoft will be a possible provider themselves (a la Office 365 and SharePoint online).

That’s about it for what’s new unless you are interested in IBM host integration there are some adapter improvements that way. For the whole article check out the BizTalk Team blog at http://blogs.msdn.com/b/biztalk_server_team_blog/archive/2011/12/08/biztalk-server-2010-r2.aspx

Until next time, see you in the funny papers.

BizTalk Server 2010 R2: Continuing story.

BizTalk Server 2010 R2: Continuing story.

Last year communication of BizTalk has been a little cloudy. Will it be discontinued, will it be dead. Richard blogged on the BizTalk future story, and Tony kept discussion very lively with his talk on World Partner Conference this year. In the roadmap on Microsoft BizTalk site a vNext after 2010 was depicted.

A new release has been announced through BizTalk Server Team Blog: BizTalk Server 2010 R2. This is great news as people wondered when next release was due. This release will be delivered six months after Windows Server 8. To me it makes sense as the release will align not only with Server 8, but also VS 2011 and SQL Server 2012. Besides platform alignment other improvements have been announced like alignment with industry standards, adapter improvements, and more tighter integration with Azure. The release does not deviate much as what was shown on existing roadmap.

image

Exact dates of release of BizTalk Server 2010 R2 are not disclosed yet. I think when it will be release it will probably be renamed BizTalk Server 2012 or BizTalk Server 8. I personally am very happy with the announcement of this release and Microsoft continuing support for this great product and dedication to keep improving it. BizTalk is not dead or going away soon and I think it to stay for a long time.

Cheers.

BizTalk Server 2010 R2 Announced

Yesterday, Microsoft announced the forthcoming release of BizTalk Server 2010 R2 on the BizTalk Server blog site. This is advanced notice, given that this new version will ship six months after the release of Windows 8, expected in the second half of next year. On this basis, we can expect the new version of BizTalk Server to arrive in 2013. Given the BizTalk team’s previous record of name changes, I wonder if this will eventually be released as BizTalk Server 2013.

Microsoft has been refreshingly open in recent months about their future plans for BizTalk Server. This strategy has not been without its dangers with some commentators refusing to accept Microsoft’s statements at face value. However, yesterday’s announcement is entirely in line with everything Microsoft has been saying, both publically and privately, for some time now. Since the release of BizTalk Server 2004, Microsoft has made little change to the core technology with, of course, the exception of a much re-vamped application packaging approach in BizTalk Server 2006. Instead, Microsoft chose to put investment into a number of important ’satellite’ technologies such as EDIFACT/X12/AS2 support, RFID Server, etc. Maintaining the stability of the core platform has allowed BizTalk Server to emerge as a mature and trusted workhorse in the enterprise integration space with widely available skills in the marketplace.

In terms of its major investments, Microsoft’s focus has long shifted to the cloud. Microsoft has candidly communicated that, given this focus, they have no current plans to add major new technologies to the BizTalk platform. In addition, they absolutely have no intention of re-engineering the core BizTalk platform. In my direct experience in recent months, this last point plays very well to prospective and existing enterprise customers. It takes us straight to the heart of what most organisations want from an integration server: a ’known quantity’ with a good track record for dependability, scalability and stability and a significant pool of available technical resource.

The announcement of BizTalk Server 2010 R2 illustrates and illuminates Microsoft’s stated future strategy for the product. An important part of Microsoft’s platform for enterprise computing, it will continue to be enhanced and extended. It will match future developments in the Windows platform and new versions of Visual Studio. However, we should not expect to see any dramatic new developments in the world of BizTalk Server. Instead, the BizTalk platform will continue to steadily mature further as the world’s best-selling integration server.

One of the big messages of yesterday’s announcement is that BizTalk Server will increasingly support its emerging role in building hybrid solutions that encompass systems and services that reside both on-premises and in the cloud. At

SolidSoft

, we are increasingly focused on the design and implementation of cloud-based and hybrid integration solutions. Integration is challenging, and Azure is a young, fast evolving platform. Microsoft has discussed at length their vision of Azure within a wider ’hybrid’ context. The availability of a tried and tested, mature, on-premises integration server is a vitally important enabler in building hybrid solutions. Better than that, the announcement makes it clear that, as well as new support for the Azure service bus, BizTalk Server 2010 R2 licensing will be revised to open up new opportunities for hosting the server in the cloud. This ties in with the push in Azure to embrace more fully the IaaS (infrastructure-as-a-service) model and, perhaps most importantly in the BizTalk space, to reduce or eliminate existing barriers between the on-premises and off-premises worlds. BizTalk Server and Azure belong together.

SQL Server 2012 Windowing Functions Part 1 of 2: Running and Sliding Aggregates

The first windowing capabilities appeared in SQL Server 2005 with the introduction of the OVER clause and a set of ranking functions (ROW_NUMBER, RANK, DENSE_RANK, and NTILE). The term “window,” as it is used here, refers to the scope of visibility from one row in a result set relative to neighboring rows in the same […]
Blog Post by: Lenni Lobel