Recently we had a requirement to integrate a RESTful Service with BizTalk Server. Well no biggie. You can use WCF – Custom Adapter and use webHTTP binding and add a webHttp Endpoint behavior. Wala. Easy to say, little bit tricky to do.
That all is fine, but what if you want to have a polling receive location which needs to go and do an HTTP GET to a RESTful Service. Aahh!! That’s even more trickier. Bunch of you reading this post would have already thought about some or other way of doing it.
1. Create a basic windows service which runs at scheduled time and drops a message into BizTalk and Biztalk picks up, a RESTful send port subscribes to that message and do the regular RESTful call.
2. Have a SQL Task to drop a message and have a RESTful SendPort to do the regular RESTful call.
3. Many more way..
But what if we can have a Receive Port itself polling at regular interval and make the RESTful Service call? This eliminates the need of unnecessary windows service or the SQL Task or any other triggering process you think of. Cool right..!!
So I came across the BizTalk Scheduled Task Adapter.
This is a task scheduling adapter which can execute a prescribed task at a configured time. It comes with few default scheduling tasks like XmlString, FileReader, HttpDownload. Also has few version of it out there which can work with almost all versions of BizTalk Server. Lot of people are using it without any issues.
How does it solve our scenario of invoking RESTful Service?
Well, I decided to write a custom Task for it which will be invoking the RESTful Service. I tried to make this component pretty generic so that anyone can use it but ofcourse, it also depends upon type of RESTful service you are invoking. Few might need authentication, keys etc. You can always extend it according to your needs. Anyways, below is how you can use it.
1. Download and install the BizTalk Scheduled Task Adapter. Here is a blog post on how you can use the defaults Tasks which comes with it.
2. Download and Open the RESTServiceAdapterProvider Project in Visual Studio. Compile the code and GAC the assembly if it does not do it by itself.
3. Open BizTalk Server Admin Console and create a new Receive Port, Receive Location under your application.
4. In the receive location properties, Adapter type = Scheduler. This is the name you give to the BizTalk Scheduled Task Adapter while configuring it. If you don’t see this make sure you go to the Platform Setting à Adapters à New Adapter and from the drop down select the Schedule Adapter and name it whatever you want. In my case, I named it as Scheduler.
5. Next click Configure next the Adapter Type. In the configuration window, type the name of Schedule Task you want to give. In this case “RESTfulScheduler”
6. Next click the Schedule tab on this window and specify the time you want this scheduler to run.
7. Next click the Task tab on the same window and under the Class, click Find Task and Click browse under Assembly Qualified Type Name and select the RESTServiceAdapterProvider.dll from the file location of the RESTServiceAdapterProvider project.
8. In the Assembly Qualified Type Name, select RESTProvider and click Select and its fully qualified name will appear at the bottom and click OK.
9. If you get Invalid Assembly class selected, make sure you Gac the RestProvider dll, close the BTS Admin Console, reopen it and restart the HostInstance and try again.
10. Next specify the URL, Content Type, WebMethod and click Apply, OK.
11. Once you are done configuring, you will see the URI as : schedule://TimeSpan/RESTfulScheduler
12. Next is according to your requirements for the message. You can have pipeline component doing bunch of stuff or have orchestration, schemas, maps, business rules for this message or have a send port subscribing to this message. Anything.
You can download the source code of the RESTfulAdapterProvider here
So, above you saw way of configuring a BizTalk Receive Location Polling a RESTful Service. Thanks for reading.