AX Integration: Royal Mail Shipping API Part 3

RoyalMail               Dyn-AX12_v_rgb

To send the SOAP headers required by the Royal Mail Shipping API we will use the functionality available in WCF to set headers and intercept and alter messages as they are being sent and received by the client.

EndPointBehaviour

We have already built a ClientMessageInspector class (see Part 1 and 2) implementing the IClientMessageInspector interface. Now we need to add this message inspector to the client’s message inspector collection.

Create a new class implementing IEndpointBehavior, add the method stubs need to implement the interface. In the ApplyClientBehaviour method we will hook up the message inspector, so that this will be used for each message that is sent or received.

We also want to pass credentials to the ClientMessageInspector, so create a public method that will set a credential variable (taking the client id and secret as string). Then call the SetCredentials method on the Message Inspector before adding it to the Message Inspector collection.

Message

The Shipping API also requires a set of SOAP and WSS namespaces to be added to the message sent from the client.

This is very straight forward to do creating a custom Message class and overriding the various OnWrite methods.

 

Message Formatter

To use our custom message with outgoing requests we implement the IClientMessageFormatter interface and add our Message class in the SerializeRequest method.

This means that our custom message will be used every time a message needs to be serialized before being sent to the remote endpoint.

 

Operation Behaviour

In turn our Message Formatter needs to be set as the proxy message formatter, we do this by utilising the IOperationBehaviour interface that has a set of methods like IEndpointBehaviour. The two interfaces differ in the scope that they effect.

We use the ApplyClientBehaviour method to add our message formatter.

Summary

We now have everything set up in the WCF part of our integration. We are modifiying the HTTP headers to send security information with our request. We have modified the namespaces and added SOAP elements to the message.

In the next Post

We will look at how to call our client proxy from X++ code.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.