Introduction

In this article we will see how we can publish a REST web service in BizTalk 2013. It's a simple example where BizTalk is consuming a POST request and returns all orders for a given customer and delivery date, with the parameters customer and delivery date is in an XML in the request body. Yes,  it's not best practice, it should be a GET request, but I'll attend to that later in another article. It is a bit more complicated to use GET, and I'll like to keep it simple for now.

We will not go into details of the orchestration and the process of getting the data from the ERP system, that is not the scope for this article.

Create the BizTalk Artifacts

  1. Create a new BizTalk Project in Visual Studio named DemoWCFRest.
  2. Create the schema for the input from the request body.
    • It may look like this

    Schema description

    • It's not necessary to promote the elements, I've done it because I use it in the orchestration when I create the request to the ERP system
    • Create the schemas you'll need to query the ERP system
  3. Now you can create the orchestration

  4. This is how you create the port on the left side:
    • Pull the Port shape from the Toolbox to the port surface and push Next
    • Give the port a name
    • Select "Create a new Port Type", give it a proper name, and select "Request-Response" as Communication Pattern, and push Next
    • Select "I'll be receiving a request an sending a response", and "Specify later" as Port binding
  5. Select the Operation in the newly port, and name it GetOrder (Identifier in the Properties window
  6. Define messages and the other shapes in the orchestration. The message you receive should be of the type OrderInfo
Now the solution is finished, and you can deploy it. Remember to sign the assembly and give it the Application Name DemoWCFRest before you deploy.

Create the Web Service

Now it's time to create the web service, and configure IIS.
  1. In Visual Studio, select TOOLS / BizTalk WCF Service Publishing Wizard
  2. Select Service endpoint, and use the adapter name WCF-WebHttp
  3. Check for "Create BizTalk receive locations ..."
  4. Choose the BizTalk application DemoWCFRest

  5. On the AppFabric Connect page, click Next
  6. Select "Create a Request-Response Receive Port"

  7. On the next page, specify the URL and check for "Allow anonymous access to the WCF service"

  8. Now go to the IIS Manager, and create a new Application Pool
    • Right click on "Application Pools" and select "Add Application Pool"
    • Use ".NET CLR Version v4.0...."
    • Managed pipeline mode: Integrated
    • Right click on the newly created application pool, and select "Advanced Settings"
    • Set the property "Identity" to a user which is in the "BizTalk Application Users" group. If the user don't have the appropriate access to the BizTalk Message Box, the web service will fail.
  9. Right click on the DemoWCFRest application under Default Web Site, and select "Manage Application / Advanced Settings.."
    • Select the created application pool
At this stage, IIS should be ready to go.

Configure the BizTalk Application

Open the BizTalk Server Administration Console, and select the new application.

  1. Go to Receive Locations, and double click the created location
  2. On the Receive pipeline use XMLReceive, and on the Send pipeline use PassThruTransmit
  3. In the text area named "HTTP Method and URL Mapping, insert following XML
    <BtsHttpURLMapping>
            <Operation Name='GetOrder' url='/getorder' />
    </BtsHttpURLMapping>

  4. It is important that the name of the operation element is the same as the operation on the port in the Orchestration. This is what links it all together.
  5. Here you can have many URL mappings to the same orchestration or to other orchestrations.
  6. Go to the Orchestration, and configure it. Create the other ports dependent of the orchestration.
  7. Right click on the DemoWCFRest application, and start it

Test it

An easy way to test the solution, is to use Fiddler, you can find it at http://www.telerik.com/fiddler. This is a very useful tool when you work with web services. You can use it as a proxy, if you consume a web service in BizTalk, you can use http://localhost:8888/ as proxy server, and then you can see the request and response for the send/receive port. You get all the content, and all the headers.

Start Fiddler, and select the map "Composer". Enter the request as shown in the figure below:

Now you should receive the XML returned by the orchestration. If you get HTTP error 500, you should check in BizTalk Server Administration Console for error messages. 

See Also

Another important place to find an extensive amount of BizTalk related articles is the TechNet Wiki itself. The best entry point is BizTalk Server Resources on the TechNet Wiki