Friday, January 26, 2007

One-Way Web Services with BizTalk Orchestrations

Today I want to pass on a nifty trick that gives you the ability to invoke 'fire and forget' one-way web services within a BizTalk orchestration.

My problem was that I wanted the port to handle delivery (including retries) and not have the orchestration wait until the result of the send was successful or not. Normally, doing this with ports is generally quite easy since you just use a one-way send port. However, with web services there is actually a trick to getting your web service to behave as a one-way service.

If you follow the standard procedure for hooking up a web service in an Orchestration you will get a request/response logical port shape. You get this even if the webmethod is a 'void' method that does not return anything. You can try creating your own port type but that causes other problems with web services since you'll get errors like AssemblyName context property was not valid unless you add special code to set some context properties.

The best solution is to inform BizTalk that the web service is 'one-way' so that the configured port type reflects this pattern. The way to do this is quite easy. All you need to do is add a parameter to your web method called SoapDocumentMethod with a specifier indicating the message pattern.

Sample code looks like this:

[WebMethod]
[SoapDocumentMethod(OneWay=true)]
public void OneWayService ()
{
}

When you add a web reference to your Orchestration project BizTalk now configures the port type to be one-way and the port shape reflects this. It's easy if you know the trick!

I'd like to thanks Matt Milner for posting the solution on the microsoft.public.biztalk.orchestration newsgroup.