Saturday, June 9, 2012

Duplex Client Program

First We have to  develop a Duplex communication service  then now we have consume that service.so please following steps:
  1. In a new website add service reference for creating Proxy.
  2. Design the new form according to requirement sothat we pass inputs as well as outputs from wcf service.
  3. Add a new class and implement callback interface for Getting or Posting results.
Write following Code in MyCall.cs

      using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Web;

      /// <summary>
      /// Summary description for MyClass
      /// </summary>
        public class MyClass : CourierTrackNamespace.ICourierTrackCallback
        {
            public MyClass()
            {
                       
            }
         public static string Info1;
         public void Result(string info)
         {
             Info1 = info;
          }
         }


                                  
Write following Code in Default.cs
           using System;
           using System.Collections.Generic;
           using System.Linq;
           using System.Web;
           using System.Web.UI;
           using System.Web.UI.WebControls;
          using System.ServiceModel;

          public partial class _Default : System.Web.UI.Page
          {
           protected void Page_Load(object sender, EventArgs e)
          {

           }
          protected void Timer1_Tick(object sender, EventArgs e)
         {
              lblres.Text = MyClass.Info1;
          }

           protected void btnOrder_Click(object sender, EventArgs e)
          {
           InstanceContext ic = new InstanceContext(new MyClass());
           CourierTrackNamespace.CourierTrackClient obj = new     CourierTrackNamespace.CourierTrackClient(ic);
           obj.PlaceOrder(int.Parse(txtinput.Text));
           Timer1.Enabled = true;
           }
         }

Write following Code in Default.aspx

  • Here Some Points to Noted:
             Timer-interval=1000; and Enabled view=false;

 

No comments:

Post a Comment