Professional Documents
Culture Documents
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Text;
using System.Threading.Tasks;
namespace WcfServiceMEP
{
[ServiceContract]
public interface IServiceMEP
{
[OperationContract(IsOneWay = true)]
void OneWayMessage();
[OperationContract(IsOneWay = false)]
string RequestReplyPattern();
}
}
ServiceClassMEP.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace WcfServiceMEP
{
public class ServiceClassMEP : IServiceMEP
{
public void OneWayMessage() {
Thread.Sleep(2000);
}
public string RequestReplyPattern() {
Thread.Sleep(5000);
return "current time of service is" + DateTime.Now.ToString();
}
}
}
App.config (Host)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.ServiceModel;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WCFWinFormHostMEP
{
public partial class Form1 : Form
{
ServiceHost sh = null;
public Form1()
{
InitializeComponent();
}
}
}
Form1.cs (Client)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WCFClientMEP
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.ServiceModel;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WCFClientMEP
{
public partial class Form1 : Form, ServiceReference2.IServiceMEPCallback
{
public Form1()
{
InitializeComponent();
}
App.Config (Host)
Form1.cs (Host)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.ServiceModel;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WCFWinFormHostMEP
{
public partial class Form1 : Form
{
ServiceHost sh = null;
public Form1()
{
InitializeComponent();
}
}
}
ServiceClassMEP.cs
sing System.Text;
u
using System.Threading.Tasks;
using System.Threading;
using System.ServiceModel;
using System.Xml.Linq;
namespace WCFServiceMEP
{
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Reentrant)]
public class ServiceClassMEP : IServiceMEP
{
public void hello()
{
string name = "Windows Communication Foundation";
Thread.Sleep(50);
OperationContext.Current.GetCallbackChannel<IServiceCallBack>().helloback(name);
}
}
}
IServiceMEP.cs
using System.ServiceModel;
namespace WCFServiceMEP
{
[ServiceContract(CallbackContract = typeof(IServiceCallBack))]
public interface IServiceMEP
{
[OperationContract(IsOneWay = true)]
void hello();
}
public interface IServiceCallBack
{
[OperationContract]
void helloback(string name);
}
}