Hi friends

In this post I'll be talking about how to make BizTalk 2010 ( Should work well with 2006 R2 , 2009 as well) with Dynamics AX 2009 using AIF based WCF Services

I am sure some of you might have done or seen the same happening through AIF based Adapter where the effort mostly lies on configuring the Adapter with set of properties (some of them eventually becoming the context properties) but since WCF is the way to go I would be focussing on how to achieve the same through the AIF based WCF Services.

So here it goes :

Prerequisities from AX side

Before one can go about consuming the service ,  the AIF based WCF Service must be explicitly exposed from the AX ( Read this http://technet.microsoft.com/en-us/library/dd309574.aspx  and  http://technet.microsoft.com/en-us/library/aa834369.aspx)

The WCF Service by default is set up on the 'basicHttpbinding' which does not allow overriding the 'HeaderInfo' which is again a prerequisite for communicating through WCF Services whether through BizTalk or any vanilla .Net Client.Hence one needs to edit the web.config for the service to set it up on 'wsHttpBinding''. Read in detail here http://msdn.microsoft.com/en-US/library/cc652581.aspx

Follow the instructions below to edit the web.config ( C:\Program Files\Microsoft Dynamics AX\50\AifWebServices)

  1. Under the <bindings> tag, add a <wsHttpBinding> tag, which includes a child <binding> tag.

  2. In the child <binding> tag, set the name attribute to a unique value, such as wsHttpBindingAuthAif.

  3. In the <service> tag for your service, set the binding attribute to wsHttpBinding.

  4. In the <service> tag for your service, set the bindingConfiguration attribute to wsHttpBindingAuthAif (or the unique name that you chose earlier in the <binding> tag).

Finally the Web.config should be looking like this :

Web.Config

<configuration>

...

<system.serviceModel>



<bindings>

<wsHttpBinding>

<binding name = "wsHttpWindowsAuthAif" />

</wsHttpBinding>

</bindings>

...

<services>

<service behaviorConfiguration = "serviceBehaviorConfiguration"

name = "Microsoft.Dynamics.IntegrationFramework.Service.SalesOrderService">

<endpoint address = "" binding = "wsHttpBinding" bindingConfiguration = "wsHttpWindowsAuthAif"

bindingNamespace = "http://schemas.microsoft.com/dynamics/2008/01/services"

contract = "Microsoft.Dynamics.IntegrationFramework.Service.SalesOrderService" />

</service>

</services>

...

</system.serviceModel>

</configuration>

BizTalk Side

Every requests that goes to AX must be targeted towards a particular Destination End Point  that must have been pre-configured from the AX side. Every request that goes to AX must have the Destination End point specified so that the Requests are directed towards the correct end point. This is how the basic Header looks like :

<headers>

<MessageId xmlns="http:=//schemas.microsoft.com/dynamics/2008/01/services">{FFF3E75E-A75C-4228-ABF0-8E3EA2483EB4}</MessageId>

<SourceEndpointUser xmlns="http://schemas.microsoft.com/dynamics/2008/01/services">MDSDEMO\Administrator</SourceEndpointUser>

<SourceEndpoint xmlns="http://schemas.microsoft.com/dynamics/2008/01/services">BizTalk</SourceEndpoint>

<DestinationEndpoint xmlns="http://schemas.microsoft.com/dynamics/2008/01/services">CEU</DestinationEndpoint>

</headers>

So the bottom line is that one must always ensure that this Header  information should always be present in the outbound message that goes out of the BizTalk Orchestration to the AX.

Now we all know that all the fields that are the part of the Header ,are not availble as a Context Proeprties ( If we use AIF Adapter , the adapter schema exposes these as context properties for us to use directly not not with directly exposed WCF Services)

So this is where one of the WCF Adapter Context Propeties comes to use ,which helps us set the HeaderInfo within the context of the BizTalk Message. - WCF.OutboundCustomHeaders

So briefly starting from scratch the following steps need to be followed on the BizTalk Side:

1. Import the AX Service meta-data using the "Consume WCF Service Wizard" that would import all the required Schema Files and port bindings along with the MultipartMessage Types and ports inside a newly created Orchestration

                                               

2. Once you have got all the schema in place , create your own message using the Multi Part message types , and before you send it out. Set the Context Property : WCF.OutboundCustomHeaders in an assignment shape within the 'Construct Message Shape'

MsgCreateAxItemDataRequest(WCF.OutboundCustomHeaders) = @"<headers><MessageId xmlns=""http://schemas.microsoft.com/dynamics/2008/01/services"">{FFF3E75E-A75C-4228-ABF0-8E3EA2483EB4}</MessageId><SourceEndpointUser xmlns=""http://schemas.microsoft.com/dynamics/2008/01/services"">MDSDEMO\Administrator</SourceEndpointUser><SourceEndpoint xmlns=""http://schemas.microsoft.com/dynamics/2008/01/services"">BizTalk</SourceEndpoint><DestinationEndpoint xmlns=""http://schemas.microsoft.com/dynamics/2008/01/services"">CEU</DestinationEndpoint></headers>";

Here the message 'MsgCreateAxItemDataRequest'is my Outbound Message and this the message where the Header Info needs to be put on . Here in the code snippet above, I have used  the same HEADER INFO that I have shown at the start

You may modify the Field Values depending upon your business requirements and can also have your way in setting this but the value this Context Property ( WCF.OutboundCustomHeaders  ) would have is the String representation of the XML.

3. Another important piece of information I wanted to highlight was that while importing the metadata from the Service ( with wsHttpBinding) , the port bindings ( bindings that you are going to import on to your WCF Send Port) are incomplete ( possibly some bug with the WCF Service Consumption wizard ) and hence you may have to set up the bindings on your own. I am attaching a binding file (WCFPortBindingsWsHttpBindingForAX.bindinginfo.xml) for the port bindings I had setup that worked well but still one may have to do some modifications depending upon the need.

Hope this post would help..Happy BizTalkinggg !!!