服务端类代码
服务契约:
[ServiceContract(CallbackContract=typeof(IserviceCallBack))] public interface IService1 { [OperationContract] string GetData(int value); } public interface IserviceCallBack { [OperationContract] string GetClientData(); }
服务实例:
[ServiceBehavior(ConcurrencyMode=ConcurrencyMode.Reentrant)] public class Service1 : IService1 { public string GetData(int value) { IserviceCallBack callback = OperationContext.Current.GetCallbackChannel(); string value1= callback.GetClientData(); return string.Format("You entered: {0} and CallValue is {1}", value,value1); } }
客户端代码
class CallBack : IService1Callback { public string GetClientData() { return "test callback value"; } } class Program { static void Main(string[] args) { Service1Client client = new Service1Client(new InstanceContext(new CallBack())); Console.Write(client.GetData(1)); Console.Read(); } }