- use the caller’s incoming request message to invoke an orchestration.
- in the orchestration use a map to transform the request message to a message format that is used to call a solicit-response send port.
- when the response from SQL Server comes back, use another map in the orchestration to transform the response message to an appropriate message format that will be sent back to the original caller.
Easy and quick, build the orchestration, deploy it to BizTalk and use the BizTalk WCF Service Publishing Wizard to expose the orchestration as a WCF endpoint.
However it just didn’t feel right. I wasn’t going to have any long running transactions and I wasn’t going to invoke several systems for a single request, so I wanted to avoid using orchestrations. An orchestration approach would mean multiple round trips to the MessageBox to publish and consume messages to/from the BizTalkMsgBoxDb and to hydrate and dehydrate the state of the orchestration. All these operations come at a cost.
In a messaging only scenarios like this an alternative approach is to move the logic to receive and send ports to reduce the amount of round trips to the BizTalkMsgBoxDb which consequently increases throughput and reduces latency of the application.
I did some research on the web on how to implement a request-response receive coupled to a solicit-response send without using an orchestration but to my surprise I didn’t come across any good samples. If you ever find yourself faced with a similar problem here are the steps necessary to implement a best practices solution:
- Start by launching the BizTalk WCF Service Publishing Wizard.
- In the wizard choose to generate a Service Endpoint, specify your binding of choice and choose to create a BizTalk receive location for the endpoint. Also choose to generate a metadata endpoint so that clients can consume the contract for the receive location.
- Next step is important, it is here where we’ll tell the wizard that it should publish a schema as a WCF service as opposed to publishing an orchestration.
- On the next screen we have the option to name the service and its operation. We’ll then have to choose a schema for the Request message and a schema for the Response message.
- Finally we’ll specify a target namespace for the service and a location for it to be deployed.
- Once the wizard completes a WCF endpoint is deployed to IIS and a receive location created in BizTalk.
- We also need to set up the send side of the solution. This can be done by creating a solicit-response WCF SQL send port in the BizTalk Server Administration Console.
- Use an appropriate filter as subscription in the send port, for instance BTS.MessageType.
- The final step is to set an outbound map and an inbound map on the send port. The outbound map will transform the message from the caller to a SQL Server request while the inbound map transforms the SQL Server response to the message format that is going back to the caller. Essentially these are the same maps that we would use in an orchestration approach.