Hello world !
Today my first tutorial on BizTalk. I’ll show you how to expose a WebService through BizTalk using the “BizTalk WCF Service Publishing wizard”.
The business case is this : I want to expose a WS that will allow a partner to send me customer invoices. These invoices processed by BizTalk might then be sent both to SAP for partner’s billing and to a datawarehouse for analysis.
- Step 1 – Prepare the data contract : Create a BizTalk project containing only 1 schema. It wil be used for the customer invoice message (Invoice.xsd). Build the project. Don’t forget to sign the assembly so that it can be deployed to GAC
- Step 2 – Prepare your Biztalk application : Create an empty biztalk application using BizTalk management console. The wizard will use this application to deploy your WCF Receive Location. Name it BizWCFTutorialApp.
Now add the schema assembly to your BizTalk application (Right CLick on BizTalk Application then Add, BizTalk Assemblies). This will be useful for the Xm lReceive Pipeline of your WCF ReceiveLocation.
- Step 3 – Run the wizard : Run the BizTalk WCF Service Publishing wizard. Choose the Service Endpoint with WCF-BasicHttp transport type, enable metadata endpoint and create BizTalk ReceiveLocation in the biztalk application BizWCFTutorialApp you’ve just created.
Then choose to publish the previously created schemas as WCF Service.
In the next screen, you should customize the Web Service description with the following operations. Use your right click :
- Rename WCF service description to “BizTalkWcfServiceTutorial“
- Rename Web Service to “InvoiceService“
- Delete default Web-Method “Operation1” because its a request / response method.
- Add a new one way web method called “setInvoice“
- Select the schema type “InvoiceSchemas.Invoice” for your request message. You will need to open the generated dll in your bin/debug folder.
Your screen should be like this :
To finish the wizard give the WCF Service a tagetnamespace (I suggest) and choose a location (I leave default). Allow anonymous access : it would be much easier for a first try.
then you should be able to create the Service and end up to the following screen.
- Step 4 : Adapt IIS & BizTalk – In order for your WS to work you might need to change a few things.
- First, as a good practice create a dedicated App Pool for your service. Go to IIS mangement console and create a new App Pool “BizTalkWcfServiceTutorialAppPool”. If you are like me and use BizTalk Server 2010, you must change the app pool .Net Framework to version 4.0. Then change your Service App Pool to the newly created one.
- Give enough privileges to your app pool by choosing the right identity. I suggest admin for development purposes.
- In BizTalk now :
- Change the name of the wizard created WCF Receivelocation called WcfService_BizTalkWcfServiceTutorial/InvoiceService to something easier like “RcvLoc_Invoice_WCF”.
- Change the ReceivePort to “RcvPort_Invoice_WCF”
- Add a send port SendPort_Invoice_WCF and make it subscribe to messages from the app ReceivePort.
- Start the application.
If you go to your WS page (normally) and everything went fine you should be able to see this page :
It migth fails because (I’ve been through this):
- When choosing message type in the WCF Publishing wizard, you select a dll and a screen shows you availables schemas types available in the assembly so that you can choose wich one to expose as a service. In fact this is not really that. If you have the same .dll deployed to gac this screen shows you the gac dll content and not the content of the dll you’ve just selected. If like me you change and change again your Message types, you should be aware of that.
- Wrong version of .Net Framework registered with IIS :
- Step 5 : Create the client application : Add a new console application project (named BizWCFTutorialClientApp) inside your already existing solution app (the one your crated for the XML Schema).
- Add a new reference to System.ServiceModel inside your project
- Add Service Reference to your previously created and deployed WS :
- Then go to your WebService address, Click GO. Check that your service, and operations are succesfully listed and name your reference InvoiceServiceReference.
- Your solution should look like below. Note that the app.config has been automatically generated.
- Now it’s time to hand code the call to your Service :
using System; using BizWCFTutorialClientApp.InvoiceServiceReference; namespace BizWCFTutorialClientApp { class Program { static void Main(string[] args) { //Use the client proxy InvoiceServiceClient client = new InvoiceServiceClient(); //Prepare the incoive Invoice i = new Invoice(); i.Id = "1"; //Add a line InvoiceLine l = new InvoiceLine(); l.ProductEAN = "123123"; l.Qty = "2"; l.TaxAmount = 0.25; l.UnitPrice = 1000; i.Line = new InvoiceLine[1]; i.Line[0] = l; try { //Create the Invoice via WS client.setInvoice(i); } catch (Exception e) { Console.Out.WriteLine("Error occured while calling the method setInvoice()"); throw e; } finally { // Always close the client. client.Close(); } Console.Out.WriteLine("Invoice created"); } } }
- Step 6 : Test your Service and see the result in BizTalk
Now you are ready to Test your WS using the client and see the results in BizTalk. F5 the project “BizWCFTutorialClientApp”. You should see the following in BizTalk :
You can see 2 lines highlighted : the older represents the XML ReceivePipeline pipeline (notice it is run under BizTalk Isolated Host), it worked OK ; and the above line represents the send pipeline : pub/sub worked and message has been succesfully sent. See content matches your client code.
VS code (schemas, client console app, and bizTalk binding) is available here. As uploads of .zip files aren’t supported, you’ll have to delete the .jpg after saving the file to your computer. Sorry about that.
I hope this tutorial is usefull to you : let me know !
Hi Rusteddev,
This entry is very usefull for me, thanks about this.
I have a question that have you ever used biztalk for intergrating 2 wcf application ? Could you post another tutor like this.
Many thanks
By: Phuoc Doan on February 10, 2011
at 09:10
Hi Phuoc,
Thank you for your feedback. I’m glad it helped you, that’s one of the reason why I made this blog. I did not practice wcf to wcf communication myself yet. I’m putting appart my C# and Biztalk skills for a while…. I’m practicing Ruby on Rails and XP programming for the time beeing. Maybe I’ll get back to BizTalk dev one day, who knows….
By: rusteddev on February 10, 2011
at 19:25
Hello,
Could you share VC Code, I can’t downolad from your blog. Mayby you can send via email to me.
By: Maciej on April 3, 2013
at 14:41
Hi,
I would like to appriciate you.This is a very good artical thanks and keep on posting more like this.
Thanks,
Purna
By: Purnachandra on February 18, 2011
at 04:11
hi
this is very nice tutorial that helps more for biztalk learner.
thanks for sending and keep on posting like this
By: rekha on April 19, 2011
at 06:35
This is very nice tutorial. I have scenario where I have to execute stored procedure for getting the data but without using pollingDataAvailableStatement and PollingDataStatement for say GetInvoice ? Any suggestion
By: Nehal on October 20, 2011
at 15:31
Hi , great post, it really helps me, I´m newbie in biztalk.
This is my first time publishing schemas and this is the best tutorial i have found. THANK YOU VERY MUCH!
But i have a problem, calling client.SetInvoice(i), i i type in the Client app.config, i get
{“Unrecognized configuration section serviceDebug. }
in InvoiceServiceClient client = new InvoiceServiceClient();
Any idea??
Thanks
MEL
By: MEL on June 8, 2012
at 16:42
Very Nice Article to understand the concept of Publish BizTalk Schema as WCF Service.
By: Sachin Kumar on February 9, 2014
at 14:17
Thanks a ton. It was very helpful for someone new to BizTalk WCF Service publishing wizard..And thanks for providng client information on invoking the service as well..great job!!
By: Dibyajyoti on March 17, 2014
at 10:12
Great Tutorial. Thanks.
By: BizTalk Newbie on March 26, 2014
at 18:25