Test your technical skills online, appear in Virtual Interview and be ready for job!
Twitter Twitter LinkedIn YouTube Google
Be Interview ready ! | Search
Make friends on DotNetFunda.com and expand your network!
Winners

Win Prizes

Announcements
Like us on Facebook
Sponsor
Top Articles Author
Wed, 23-Apr-2014 Authors
All Time Authors
Sourav.Kayal
39750
Sheonarayan
34800
Niladri.Biswas
33350

Latest members | More ...


(Statistics delayed by 5 minutes)
Ads

How to consume ASP.NET Web Service in BizTalk Server 2006

SheoNarayan
Posted by under BizTalk Server category on for Intermediate level | Views : 15627 red flag
If you found plagiarised (copied) or inappropriate content,
please let us know the original source along with your correct email id (to communicate) for further action.
Rating: 5 out of 5
1 vote(s)


In this article, I am going to show how to consume ASP.NET Web Services in BizTalk Server 2006.

Introduction

While working with BizTalk Server, we normally come across a situation where we need to send a request to web service and get the response into Orchestration and process the data. In this article, I am going to show how to consume an asp.net web service into BizTalk Server 2006 R2.

In order to do that first I shall create a simple web service that will accept a class that has two properties FirstNumber and SecondNumber. I have a web method called sum that will add both number and gives response back.

Creating Web Service

Below is the my web service code and my url of the webservice is http:// localhost/SampleWebService/SampleWebService.asmx , the obvious reason for localhost is because it is hosted on the same computer.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.Services;

namespace SampleWebService

{

/// <summary>

/// Summary description for Service1

/// </summary>

[WebService(Namespace = "http://tempuri.org/")]

[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

[System.ComponentModel.ToolboxItem(false)]

// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.

// [System.Web.Script.Services.ScriptService]

public class Service1 : System.Web.Services.WebService

{

[WebMethod]

public string HelloWorld()

{

return "Hello World";

}

[WebMethod]

public string Sum(SumClass sum)

{

return (sum.FirstNumber + sum.SecondNumber).ToString();

}

}

}

Code for SumClass is

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

namespace SampleWebService

{

public class SumClass

{

private int _firstNumber = 0;

public int FirstNumber

{

get { return _firstNumber; }

set { _firstNumber = value; }

}

private int _secondNumber = 0;

public int SecondNumber

{

get { return _secondNumber; }

set { _secondNumber = value; }

}

}

}

Creating BizTalk Server Application

Now, Create a blank BizTalk Server project named “ConsumeWebServiceDemo”. Right click the project and click Add Web Reference ….. Enter the url of the web service and click Go, you should see the web service. Enter “SampleWebService” in the Web reference name: box and click Add Reference. This will create a Web reference in your project with following file.

Reference.map
Reference.odx
Reference.xsd
SampleWebService.disco
SampleWebService.wsdl

Now, right click the project and click Add > New Item …. Click Categories as Schema Files and select Schema from the Template and enter the name as SourceSchema.xsd and click Add button. Modify the schema so that it looks like in picture below.



Again, add one more Schema file named DestinationSchema.xsd modify it as shown in the picture below.

Now, right click the project and click Add > New Item … Select Orchestration Files from Categories and BizTalk Orchestration from Templates and name it as “ConsumeWebServiceOrchestration.odx”

Get solutions of the .NET problems with video explanations, .pdf and source code in .NET How to's.

Creating Message


Now go to Orchestration View (If not visible, go to View > Other Windows > Orchestration View), right click Message node and click New Message. In the same way create following message.

  1. messageRec – with message type - ConsumeWebServiceDemo.SourceSchema
  2. messageWebReq – wth message type - ConsumeWebServiceDemo.SampleWebService.Service1_.Sum_request (from Web Message Types)
  3. messageWebRes – with message type - ConsumeWebServiceDemo.SampleWebService.Service1_.Sum_response (from Web Message Types)

Creating Map

Right click project and click Add > New Item … select Map Files from categories and Map from Templates and name it as “SourceToWebMap.btm”.
For source Schema select “ConsumeWebServiceDemo.SourceSchema” and for destination schema select ConsumeWebServiceDemo.SampleWebService.Reference and map like displayed in the picture below.


Building Orchestration

Drag Receive icon from Toolbox and select Activate = true, message = messageRec from Properties window.

Drag a Send icon from the toolbox and select message = messageWebRes from properties window.

Drag a ConstructMessage from toolbox, place it in between Receive and Send and select Messages Constructed = messageWebReq from properties window.

Drag a Transform icon from the toolbox and click … from Input Message in the properties window. A dialogue box appears. Select Existing Map, select the map “ConsumeWebServiceDemo.SourceToWebMap”. For Source select messageRec in in the Source Transform section. For Destination select messageWebReq.sum1 from Destination Transform section. Click OK (refer to image below for more info).

Creating Web Port


Right click Port Surface area (at the left side) and click New Configured Port …  click Next, enter name as “WebPort” click Next. Select Use an existing Port Type and select “ConsumeWebServiceDemo.SampleWebService.Service1_.Service1 under Web Port Types. Click Next and leave Port Binding to Specify Now and click Next. Click Finish.

Drag one more Send icon from toolbox and place in between ConstructMessage and Send. Select message = messageWebReq from properties window. Attach this send to Request of the Sum web port.
Drag one more Receive icon from toolbox and place between 2nd Send and 3rd Send. Select message = messageWebRes from properties window. Attach this receive to Response of to Sum web port (as displayed in the picture below).

Creating Port


Right click Surface area (in the right side) and click “New Configured Port …” click Next. Enter name as “RecPort” click Next and enter “RecPortType” click Next . Select “I’ll always be receiving messages on this port.” from Port direction of communication dropdown. Leave the second dropdown default. Click Finish.

Again, right click Surface area (in the right side) and click “New Configured Port …” click Next. Enter name as “SendPort” click Next and enter “SendPortType” click Next . Select “I’ll always be sending messages on this port.” from Port direction of communication dropdown. Leave the second dropdown default. Click Finish.

Now attach the top receive to the “RecPort” and bottom Send to “SendPort” you just created (If for any reason bottom Send is not getting attached with SendPort, click on the ! red color icon besire Send icon and create a Send port in the same way you created the Send port above, you need to delete the Send port if you have created by following earlier steps of creating Send Port.)

My orchestration ConsumeWebServiceOrchestration.odx looks like below.

Building the application

Now right the project and click Assembly, specify the Assembly Key File name (.snk file). Click on Deployment under Configuration Properties and specify the Application Name as “ConsumeWebServiceDemo”.

Now build again and deploy the application by right clicking the project.

Configuring Port

Go to BizTalk Server 2006 Administration Console and right click the ConsumeWebServiceDemo application and click Configure … configure Bindings information for RecPort and SendPort as displayed in the below picture. To know how to configure the File Adapter, you can read my previous article http://www.dotnetfunda.com/articles/article275.aspx.



Now right click the ConsumeWebServiceDemo application and click Start. Place the sample xml file by generating instance of the SourceSchema.xsd file and placing in the input folder. The Sample source xml file will be (name it whatever you like for example test.xml). Refer to my earlier article http://www.dotnetfunda.com/articles/article275.aspx for more details.

<ns0:SourceRoot xmlns:ns0="http://ConsumeWebServiceDemo.SourceSchema">  <FirstNumber>10</FirstNumber> 
  <SecondNumber>10</SecondNumber>
  </ns0:SourceRoot>


After few moment you will see an .xml file in the output folder something like this

<?xml version="1.0" encoding="utf-8"?>
<string>20</string>

COOL !! So we have consumed a Web service into the BizTalk Server 2006 Orchestration. Please let me know if you have faced any difficulties while building your own application. Good Luck and happy coding !!!

Page copy protected against web site content infringement by Copyscape
Found interesting? Add this to:




About the Author

SheoNarayan

Full Name: Sheo Narayan
Member Level: HonoraryPlatinum
Member Status: Microsoft_MVP,Administrator
Member Since: 7/8/2008 6:32:14 PM
Country: India
Regards, Sheo Narayan The Founder http://www.dotnetfunda.com
http://www.snarayan.com

Microsoft MVP, Author, Writer, Mentor & architecting applications since year 2001. Connect me on http://www.facebook.com/sheo.narayan | https://twitter.com/sheonarayan | http://www.linkedin.com/in/sheonarayan
Login to vote for this post.

Comments or Responses

Posted by: Poster on: 4/3/2009

Hi Sheo Sir,

This article is really very simple and easy to follow. I could get this working in the first shot itself.

Thank your very much.

Posted by: Hsingh78 on: 8/20/2012 | Points: 25

Hi,

First of all thanks to this nice article. While in the middle i got stuck at where we need to create messages:

messageWebReq – wth message type - ConsumeWebServiceDemo.SampleWebService.Service1_.Sum_request (from Web Message Types)
messageWebRes – with message type - ConsumeWebServiceDemo.SampleWebService.Service1_.Sum_response (from Web Message Types)

I dont see these message types to choose from while creating the message. Actually i am trying to do something simple, i have a web service and want to see how Biztalk can talk to it and get a value out of it. Do you have an email i can reach out to you. Pls help

Thanks

Posted by: Tiagosumita on: 1/10/2014 | Points: 25

Really OUTSTANDING article.
Unfortunately is very hard to find a Biztalk tutorial that is consistent, organized and complete as this one, thank you very much.

Posted by: Sheonarayan on: 1/10/2014 | Points: 25

Thanks Tiagosumita !


Login to post response.

Comments / Responses
Select text & click toolbar to format. Formatting appears in viewmode only. HTML Tags are not allowed.
Bold Italic Underline Paragraph Title Code  Link 
 Wait ... Processing ..... please wait.

Comment using Facebook