Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Responsive WCF service With ICallbackEventHandler Interface

, 8 Feb 2013
Responsive WCF service with ICallbackEventHandler Interface.
AspNetWcfDuplexDemo-noexe.zip
AspNetWcfDuplexDemo
Service
App_Code
DemoService.svc
Properties
Service.csproj.user
WebClient
Properties
Service References
DemoService
configuration.svcinfo
configuration91.svcinfo
DemoService.disco
DemoService.wsdl
Reference.svcmap
WebClient.csproj.user
AspNetWcfDuplexDemo.zip
bin
Service.dll
DemoService.svc
Service.csproj.user
bin
WebClient.dll
configuration.svcinfo
configuration91.svcinfo
DemoService.disco
DemoService.wsdl
Reference.svcmap
WebClient.csproj.user
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebClient.DemoService;
using System.ServiceModel;
using System.Threading;

namespace WebClient
{

    public class CallBack : WebClient.DemoService.IDemoServiceCallback
    {

        public string Message
        {
            get;
            set;
        }
        public void ISOrerPlaceSuccessfully(bool issuccess, float total)
        {
            Thread.Sleep(5000);
            if (issuccess)
                this.Message = "Order with total of : " + total + " placed successfully";
            else
                this.Message = "Order with total of : " + total + " failed to place";
        }
    }

    public partial class Default : System.Web.UI.Page, ICallbackEventHandler
    {
        static CallBack callback;
        DemoServiceClient client;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                try
                {
                    //setupClientSideCallback();

                    Response.Write("abc");
                    Server.MapPath("abc.aspx");
                }
                catch
                {
                }
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            setupClientSideCallback();
            callback = new CallBack();
            InstanceContext ic = new InstanceContext(callback);
            client = new DemoServiceClient(ic);
            OrderItem item = new OrderItem();
            item.Name = "Test";
            item.Price = 12;
            item.Quantity = Convert.ToInt32(txtQunatity.Text);
            lblMsg.Text = "Placing Order...";
            client.PlaceOrder(item);
        }


        protected void setupClientSideCallback()
        {
            string ScriptRef = this.ClientScript.GetCallbackEventReference(this, "'" + 0 +

        "'", "OnCallback", "'" + lblMsg.ClientID + "'");

            formBody.Attributes.Add("onload", ScriptRef);
            string script = "<script language='javascript' type='text/javascript'> " +

                         " function getServerTime() " +

                         " { " + ScriptRef + " } " +

                         " function OnCallback(Result,Context) " +

                         " { " +

                         " var lbl=document.getElementById(Context); " +

                          " lbl.innerText=Result ; " +

                          " setTimeout(getServerTime, 1000); " +

                          " } " +

                         " </script> ";

            this.ClientScript.RegisterClientScriptBlock(this.GetType(), "ClientCallback", script);

        }

        string ICallbackEventHandler.GetCallbackResult()
        {
            if (callback!=null && callback.Message != null)
            {
                return  callback.Message;
            }

            return "Placing Order..." ;
        }

        string eventArgument;

        void ICallbackEventHandler.RaiseCallbackEvent(string eventArgument)
        {
            this.eventArgument = eventArgument;
        } 
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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

About the Author

Pranay Rana
Software Developer (Senior) GMind Solusion
India India

Microsoft C# MVP (12-13)

 
Hey, I am Pranay Rana, working as a ITA in MNC. Web development in Asp.Net with C# and MS sql server are the experience tools that I have had for the past 5.5 years now.
 
For me def. of programming is : Programming is something that you do once and that get used by multiple for many years
 

You can visit my blog

StackOverFlow - http://stackoverflow.com/users/314488/pranay
My CV :- http://careers.stackoverflow.com/pranayamr
 
Awards:


Follow on   Twitter   LinkedIn

| Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 8 Feb 2013
Article Copyright 2012 by Pranay Rana
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid