Duplex Service in WCF Step By Step Tutorial

Here code for IService1.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

namespace WcfService
{
[ServiceContract(SessionMode = SessionMode.Required, CallbackContract = typeof(IService1Callback))]
public interface IService1
{
[OperationContract(IsOneWay = true)]
void AddNumber(int number);
}
public interface IService1Callback
{
[OperationContract(IsOneWay = true)]
void Calculate(int result);
}
}


Here codes for Service1.svc.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

namespace WcfService
{
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
public class Service1 : IService1
{
public void AddNumber(int number)
{
callback.Calculate(number + 10);
}
IService1Callback callback
{
get { return OperationContext.Current.GetCallbackChannel(); }
}
}
}


Web.config မှာ ထပ်ပြီး system.serviceModel => services=> endpoint ရဲ့ binding method ကို wsDualHttpBinding လို့ ပြင်ပေးရပါမယ် .. ဒါမှ Duplex Callback method က အလုပ်လုပ်မှာ ဖြစ်ပါတယ် ..
Codes for Form1.cs
Form1 have only 1 button ..




using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.ServiceModel;
using System.ServiceModel.Channels;

namespace Client
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
InstanceContext instanceContext = new InstanceContext(new MyCallback());
ServiceReference1.Service1Client svcClient = new Client.ServiceReference1.Service1Client(instanceContext);
svcClient.AddNumber(33);
}
public class MyCallback : ServiceReference1.IService1Callback
{
public void Calculate(int result)
{
MessageBox.Show("result=" + result.ToString());
}
}
}
}


Here some useful links ...
http://www.c-sharpcorner.com/UploadFile/dhananjaycoder/3189/

http://netprogramminghelp.com/wcf/how-to-createperform-duplex-service-contracts-in-wcf/

http://www.codeguru.com/csharp/.net/net_wcf/article.php/c17831__1/Creating-a-Duplex-Service-in-Windows-Communication-Foundation-WCF.htm

MSDN link

No Response to "Duplex Service in WCF Step By Step Tutorial"

Post a Comment

powered by Blogger