Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / web / ASP.NET

BizTalk 2006 Consuming a Web Service and Publishing Orchestration as Web Service and Calling from ASPX

2.30/5 (8 votes)
14 May 2008CPOL 1   508  
This sample shows BizTalk 2006 consuming a Web Service, then publishing orchestration as a Web Service, and calling it from ASPX.

Introduction

One of our client projects comprises of accessing data across different Web Services. They wanted to integrate all of them to perform their business process. Instead of calling all the Web Services individually, they want to carry out their business logic using some mechanism which will integrate them to a central location.

To provide them with a mechanism to integrate different services, BizTalk comes into picture which will provide a solution to centralize the business processes for communication and accessing data across them.

Image 1

Background

In the actual scenario, I will be consuming a third party Web Service, but here for the demo, I am creating my one Web Service.

Image 2

Using the code

Here we are consuming two Web Services, GetAdvt and GetWidget, in our orchestration and saving their output to a SQL Server table, and then rendering it to an ASPX page by calling Published Orchestration.

Here is the code to call the published orchestration on ASPX:

C#
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Xml;
using System.Xml.Xsl;
using System.Xml.XPath;
using System.Web.Caching;
using System.Data.SqlClient;

//using SKCV_GetPage; //Add Web service
public partial class LandingPage : System.Web.UI.Page
{
    private string ContentMetaData4 = "";
    private static XslCompiledTransform transform = new XslCompiledTransform();
    private string lReqOn = "", lOrchCompleted = "", 
            lDataInsert = "", lOrchInvok="";

    protected void Page_Load(object sender, EventArgs e)
    {
    }

    protected void cmdGetPage_Click(object sender, EventArgs e)
    {
        try
        {
            lReqOn = System.DateTime.Now.ToString();
            CallBizTalkWS();//Call BizTalk Published Orchestration WS
            lOrchCompleted = System.DateTime.Now.ToString();
            System.Threading.Thread.Sleep(2000);//delay for 2 Sec.
            //Geting Data From PublishContents Table
            DoTransformation(Convert.ToInt16(txtpageId.Text), 3, 2);
            Xml1.DocumentContent = ContentMetaData4.Replace("xmlns", "xmlns:xsl");
            //Geting Data From PublishContents Table
            DoTransformation(Convert.ToInt16(txtpageId.Text), 99, 2);
            Xml2.DocumentContent = ContentMetaData4.Replace("xmlns", "xmlns:xsl");

            //Diaplying Times
            labUserId.Text = txtuserId.Text;
            labReqOn.Text = lReqOn;
            labOrchInvok.Text = lOrchInvok;
            labOrchCompleted.Text = lOrchCompleted;
            labDataInsert.Text = lDataInsert;
            labRender.Text = System.DateTime.Now.ToString();
        }
        catch (Exception lException)
        {
            Response.Write(lException.Message.ToString());
        }
    }

# region "Private Functions"
    private void CallBizTalkWS()
    {
        SKCV_GetPage.InPara lInPara = new SKCV_GetPage.InPara();
        lInPara.userId = txtuserId.Text;
        lInPara.pageId = txtpageId.Text;
        SKCV_GetPage.WebService_SKCV_GetPage lGetPage = new SKCV_GetPage.WebService_SKCV_GetPage();
        IAsyncResult lIAsyncResult;

        // Begin the Async call to WS
        lIAsyncResult = lGetPage.BeginOperation_1(lInPara,null, null);

        // Wait for the asynchronous operation to complete.
        lIAsyncResult.AsyncWaitHandle.WaitOne();

        lGetPage.EndOperation_1(lIAsyncResult);

        if (lIAsyncResult.IsCompleted)
        {
            //labMsg.Text = "WS Completed" ;
            //Geting Data From PublishContents Table
            //DoTransformation(Convert.ToInt16(txtpageId.Text), 3, 2);
            //Xml1.DocumentContent = ContentMetaData4.Replace("xmlns", "xmlns:xsl");
            //Geting Data From PublishContents Table
            //DoTransformation(Convert.ToInt16(txtpageId.Text), 99, 2);
            //Xml2.DocumentContent = ContentMetaData4.Replace("xmlns", "xmlns:xsl");
        }
    }

    private void DoTransformation(int PageId, int PositionId, int ContentId)
    {
        //int PageId = 0, PositionId, ContentId;
        string Content = "", ContentMetaData1 = "", 
               ContentMetaData2 = "", ContentMetaData3 = "";
        SqlConnection lCon = new SqlConnection(
          ConfigurationManager.ConnectionStrings["ConnectionString"].ToString());
        lCon.Open();

        using (lCon)
        {
            SqlCommand lCmd = lCon.CreateCommand();
            lCmd.CommandType = CommandType.StoredProcedure;
            lCmd.CommandText = "SelectPublishContents";
            SqlDataAdapter lAdp = new SqlDataAdapter();
            lAdp.SelectCommand = lCmd;
            SqlParameter lPageId = new SqlParameter("@PageId", SqlDbType.Int);
            lPageId.Value = PageId;//Convert.ToInt16(txtpageId.Text);
            SqlParameter lPositionId = new SqlParameter("@PositionID", SqlDbType.Int);
            lPositionId.Value = PositionId ;
            SqlParameter lContentId = new SqlParameter("@ContentId", SqlDbType.Int);
            lContentId.Value = ContentId ;

            lCmd.Parameters.Add(lPageId);
            lCmd.Parameters.Add(lPositionId);
            lCmd.Parameters.Add(lContentId);
            SqlDataReader lReder;
            lReder = lCmd.ExecuteReader();

            if (lReder.HasRows)
            {
                while (lReder.Read())
                {
                    PageId = Convert.ToInt16(lReder["PageId"].ToString());
                    PositionId = Convert.ToInt16(lReder["PositionId"].ToString());
                    ContentId = Convert.ToInt16(lReder["ContentId"].ToString());
                    Content = lReder["Content"].ToString();
                    ContentMetaData1 = lReder["ContentMetaData1"].ToString();
                    ContentMetaData2 = lReder["ContentMetaData2"].ToString();
                    ContentMetaData3 = lReder["ContentMetaData3"].ToString();
                    ContentMetaData4 = lReder["ContentMetaData4"].ToString();
                    lDataInsert = lReder["CreatedOn"].ToString();
                    lOrchInvok = lReder["ContentMetaData2"].ToString();
                }
            }
        }
    }
#endregion
}

Points of Interest

I am calling a Web Service asynchronously using "CallBizTalkWS()". Here you will find an example of SOAP and SQL Adapter too.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)