Service Bus for Windows Server – Posting messages for BizTalk

In my previous post I talked about how we are using Service Bus as our queueing mechanic, from which we read messages using BizTalk. When using Paulo Salvatori’s test client we could read these messages in BizTalk, however when we were publishing messages from our own .NET applications, we weren’t able to receive them in BizTalk. These were the errors we got in the event log:

The adapter “WCF-Custom” raised an error message. Details “System.ServiceModel.CommunicationException: Unrecognized message version.

The adapter “WCF-Custom” raised an error message. Details “System.FormatException: Input string was not in a correct format.

Error
After some research, I found out this is due to the way the messages are being deserialized by the BizTalk WCF adapter. To solve this, when placing the messages on Service Bus, we have to publish them as WCF messages, instead of using the Service Bus SDK.
Continue reading

Create webservice in non default website using BTDF

For our current customer, we have both WCF and SOAP webservices we want to expose, however IIS does not allow these 2 different types to live under the same website.
Therefore, I would have to create one of the webservices in a non-default website.
I wanted to use the BizTalk Deployment Framework for this, to make deployment easy, and to make sure the webservices would always be deployed to the correct website.
After some research, I found out this can be done by adding the following line to the first property group in your .btdfproj file:

<IISMetabasePath>IIS://localhost/w3svc/2/Root</IISMetabasePath>

Here you only have to change the 2 to the ID of the website under which you want the webservice to run, which can be found by opening the advanced properties of the website in IIS Manager.

IIS website advanced properties

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