Integrating Microsoft Dynamics CRM 2011 with BizTalk 2010

As I told in my previous post, I am working at a customer where we are trying to integrate Microsoft Dynamics CRM 2011 using BizTalk 2010. Since CRM 2011 does not have a BizTalk adapter anymore, we have to use the webservices it exposes, which can be used in BizTalk in 2 ways. I first tried to use the untyped option, where you would have to use mappings with custom XSLT for your communication to the CRM service. I ran into a lot of problems with this, and then decided to use the typed option instead. Using this option, you will create a helper class that does the communication to CRM, which you can then use from your orchestrations. While looking for more resources on this, I ran into this video Peter Kelcey created, which I used as my basis for my solution. The full source for my solution can be found here.
Continue reading

Integrating CRM 2011 with BizTalk 2010 – Untyped

At one of our customers we are running a project where we are integrating various systems, among which a hosted CRM 2011 on premise. In older versions of CRM we had a BizTalk adapter which could be used to set up communication between BizTalk and CRM, however with this version this is no longer the case. Microsoft has decided integration should be done by using the new webservices CRM exposes, which sounds easier then it turned out to be.
Continue reading

Automated creating of users and groups

In my previous post I showed how I automated creating hosts and host instances. In this post I will continue on that, but then by creating the users and groups according to the BizTalk best practices. They are created on the local computer, I will see if I can adjust the script to create them in an AD at a later time. As with my last post, I have commented my code thoroughly, so it should pretty much explain itself.
Continue reading

Automated creating of BizTalk hosts and host instances

I regularly have to do new deployments of BizTalk environments. Off course I try to follow the best practices as best as I can, which means I always try to have a seperate send, receive, orchestration and tracking host. Because I don’t want to spend to much time creating these, I decided to make a PowerShell script to do this for me. I used the BizTalk PowerShell Provider to do so. This blogpost will show the code I used. I commented my code, so it should be pretty self-explanatory.
Continue reading

Deploy webservice using BizTalk Deployment Framework

In one of my projects we expose schema’s as a WCF webservice. I wanted to use the BizTalk Deployment Framework to deploy the webservice along with all the other artifacts. Start by deploying the webservice using the BizTalk WCF Service Deployment Wizard. Once finished, copy the folder for the webservice from C:\inetpub\wwwroot to your project folder. After you have added the files to your project, make sure the build action on the XSD’s is set to None instead of BtsBuild, as the references in these schemas probably can’t be resolved on build. Now you have to make a couple changes in your BTDF project file. To start with, you will have to tell that you want to deploy virtual directories, change the following property to do so:

<IncludeVirtualDirectories>true</IncludeVirtualDirectories>

After the virtual directories have been created IIS has to be restarted. Luckily, this can also be done using BTDF, by setting the SkipIISReset property.

<SkipIISReset>false</SkipIISReset>

Next you will have to specify the settings of the webservice. For this create a new ItemGroup, which should be placed under the PropertyGroup with the ProductID.

<ItemGroup>
  <VDirList Include="*">
    <Vdir>NameOfWebService</Vdir>
    <AppPool>NameOfAppPoolToRunServiceUnder</AppPool>
    <Physdir>..\NameOfWebserviceFolderYouCopiedEarlier</PhysDir>
  </VDirList>
</ItemGroup>

You will also have to specify the user credentials the AppPool will run under. I used the SettingsFileGenerator.xml file for this. Add VDIR_UserName and VDIR_UserPass to this document, and set them for your environments. Now go back to the BTDF project file, and add the following under the ItemGroup you just created.

<ItemGroup>
  <PropsFromEnvSettings Include="VDIR_UserName;VDIR_UserPass" />
</ItemGroup>

Standard, the AppPool will be running .NET2, however we want it running .NET4. In the final release of BTDF v5 there will be a new attribute on the VDirList for this, but for now we have to use a CustomPostDeployTarget.

<Target Name="CustomPostDeployTarget">
  <Exec Command="&quot;C:\Windows\System32\inetsrv\appcmd.exe&quot; set APPPOOL /apppool.name:&quot;NameOfAppPoolToRunServiceUnder&quot; /managedRuntimeVersion:v4.0 /managedPipelineMode:Integrated" />
</Target>

Now when you use the BTDF to deploy your application, it will automatically set up an AppPool and create the WCF webservice for you.

Expose schema as WCF service

Today we ran into a small problem while exposing a schema as a WCF service. We could open the service in our browser, we would see the service.

Webservice runningHowever when trying to add the service as a reference in Visual Studio we got the following error:
The document at the url http://biztalk.customer.com/RetreiveContact/RetreiveContact.svc was not recognized as a known document type.
The error message from each known type may help you fix the problem:
– Report from ‘XML Schema’ is ‘The document format is not recognized (the content type is ‘text/html; charset=UTF-8′).’.
– Report from ‘http://biztalk.customer.com/RetreiveContact/RetreiveContact.svc’ is ‘The document format is not recognized (the content type is ‘text/html; charset=UTF-8′).’.
– Report from ‘DISCO Document’ is ‘There was an error dowcomoading ‘http://biztalk01/RetreiveContact/RetreiveContact.svc?disco’.’.
– The remote name could not be resolved: ‘biztalk01’
– Report from ‘WSDL Document’ is ‘The document format is not recognized (the content type is ‘text/html; charset=UTF-8′).’.
Metadata contains a reference that cannot be resolved: ‘http://biztalk.customer.com/RetreiveContact/RetreiveContact.svc’.
Metadata contains a reference that cannot be resolved: ‘http://biztalk.customer.com/RetreiveContact/RetreiveContact.svc’.
If the service is defined in the current solution, try building the solution and adding the service reference again.
Now the trick is in this part: – The remote name could not be resolved: ‘biztalk01’. We are contacting the machine from the outside, but our service points to an internal server. To change this, I went into the IIS manager, opened Sites -> BizTalk Site, and opened the bindings. Here I edit the http binding, and changed the hostname to biztalk.customer.com, and after restarting the website we could now succesfully import the service in Visual Studio.

Edit bindings

Add additional assemblies to the GAC using BTDF

Using the BizTalk Deployment Framework it is very easy to add additional assemblies to the GAC along with the rest of your application. Just add the following code to the BTDF project file:

<ItemGroup>
    <ExternalAssemblies Include="Assembly1.dll">
        <LocationPath>..PathToAssembly</LocationPath>
    </ExternalAssemblies>
    <ExternalAssemblies Include="OtherAssembly.dll">
        <LocationPath>C:SharedAssemblies</LocationPath>
    </ExternalAssemblies>
</ItemGroup>

One thing to note, is the position where this piece of code should be placed. The BTDF project file should be organized as this:
<PropertyGroup>’s
<ItemGroup>’s
<Import Project=”$(DeploymentFrameworkTargetsPath)BizTalkDeploymentFramework.targets” />

Using 64bit Host Instance

When testing an orchestration today, I ran into the following error:

xlang/s engine event log entry: Uncaught exception (see the ‘inner exception’ below) has suspended an instance of service ‘CRMTest.Orchestrations.GetAccountName(2b505d60-0c8f-4ebf-0280-f35d2da71685)’.
The service instance will remain suspended until administratively resumed or terminated.
If resumed the instance will continue from its last persisted state and may re-throw the same unexpected exception.
InstanceId: 5dd0d288-f280-446b-8362-c34b3e6cc38f
Shape name: Rcv_accountNameRequest
ShapeId: cfd98de6-2bcf-43e0-85d4-c8d6596aba74
Exception thrown from: segment 1, progress 3
Inner exception: Exception has been thrown by the target of an invocation.
Continue reading

BizTalk360 and DTC

At one of our customers I have set up BizTalk360 as their BizTalk monitoring environment. All in all, they are very happy with it, but we ran into one problem. When they tried to suspend or resume an instance, they would get the following error:

Unable to enlist in the transaction.
System.Runtime.InteropServices.COMException (0x8004D00A): Unable to enlist in the transaction.
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
at System.Management.ManagementObject.InvokeMethod(String methodName, ManagementBaseObjectinParameters, InvokeMethodOptionsoptions)
at System.Management.ManagementObject.InvokeMethod(String methodName, Object[] args)
at A.cf0555bb9c0f6a0aebd67da53b41e6535.cc49ef4e8476b31546c8cfd644bd22a66(String c3ce089d4844970dd178d4bf819010021)
at Kovai.BizTalk360.BusinessService.Main.BizTalkQueryBusinessService.ExecuteServiceInstanceOperation(ServiceInstances serviceInstances, ServiceInstanceOperationoperation)
at Kovai.BizTalk360.WCFService.BizTalkQueryService.ExecuteServiceInstanceOperation(BizTalkQueryServiceRequest request, ServiceInstances serviceInstances, ServiceInstanceOperation operation)

After some research, I found out this was a problem with the DTC service, which was not enabled on the BizTalk360 machine. To solve it, follow these steps (on Windows Server 2008 R2).

First open  the Component Services snap-in by giving the command dcomcnfg in the start menu. In the tree, open Component Services, Computers, My Computer, Distributed Transaction Coordinator, and finally right-click on Local DTC and select properties. Go to the Security tab, enable Network DTC Access, Allow Inbound and Allow Outbound, and click OK.Now restart your BizTalk360 service, and things should be working.

BizTalk Powershell Provider on Windows Server 2008 R2

Today I ran into a problem while trying to use the BizTalk PowerShell Provider on a Windows Server R2 installation. I allready knew I would have to use the 32 bit version when working with the provider, however on starting up the console I received the following message:
Add-PSSnapin : Cannot load Windows PowerShell snap-in BizTalkFactory.Powershell.Extensions because of the following err or: Could not load file or assembly ‘file:///C:Program Files (x86)BizTalkFactory PowerShell ProviderBizTalkFactory.P owerShell.Extensions.dll’ or one of its dependencies. This assembly is built by a runtime newer than the currently load ed runtime and cannot be loaded. At C:UsersAdministratorDocumentsWindowsPowerShellprofile.ps1:5 char:13 + Add-PSSnapin <<<< BizTalkFactory.Powershell.Extensions + CategoryInfo : InvalidArgument: (BizTalkFactory.Powershell.Extensions:String) [Add-PSSnapin], PSSnapInE xception + FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.AddPSSnapinCommand

In the documentation for the provider it states it targets .NET 2.0, and that the configuration files should be changed to the following:

1
2
3
4
5
<configuration>
  <startup>
    <supportedRuntime version="v4.0.30319" />
  </startup>
</configuration>

This did however not solve my problem. After further investigation I found out you actually need following in the PowerShell configuration file:

1
2
3
4
5
6
<configuration>
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0.30319" />
    <supportedRuntime version="v2.0.50727" />
  </startup>
</configuration>

On a x64 system this file can be found here:

C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe.config

If the file does not yet exist, simply create it.