Click here to Skip to main content
Licence CPOL
First Posted 22 Oct 2007
Views 21,577
Downloads 173
Bookmarked 22 times

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

By | 14 May 2008 | Article
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.

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.

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:

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)

About the Author

thawait.himanshu

Technical Lead
www.igatepatni.com
United States United States

Member

Himanshu Thawait is from Pune INDIA, He is Currently Working with iGatePatni Americas Inc., As a Tech Lead
 
Himanshu has more than 8+ yrs of experience in the IT industry working on Microsoft Technologies. He is involved in various project activities like System Architecture, Design, and Development. Technical experience most specifically ASP.NET, WCF and Webservices, Biztalk 2006, Design Pattern , C# and .NET framework
He has strong knowledge of Enterprise Business Application Domain

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
General[Message Removed] PinmemberMojtaba Vali1:01 25 May '08  
QuestionUsing the BizTalk Published Web Service PinmemberKevin Seah6:22 14 Nov '07  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 14 May 2008
Article Copyright 2007 by thawait.himanshu
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid