日期:2014-05-17 浏览次数:21196 次
[ServiceContract(CallbackContract = typeof(ICalculatorDuplexCallback))] public interface ICalculator { [OperationContract] void SendMessage(string message); } public interface ICalculatorDuplexCallback { [OperationContract] void ServerReply(string originalMessage); }
public void ServerReply(string originalMessage) { Console.WriteLine("{0} 收到服务器回复:{1}", DateTime.Now, originalMessage); }
WSDualHttpBinding binding = new WSDualHttpBinding(); EndpointAddress endptadr = new EndpointAddress("http://localhost:12000/DuplexTestUsingCode/Server"); binding.ClientBaseAddress = new Uri("http://localhost:8000/DuplexTestUsingCode/Client/"); CallbackHandler callback = new CallbackHandler(); CalculatorClient client = new CalculatorClient(new InstanceContext(callback), binding, endptadr); Console.Write("请输入:"); string input = Console.ReadLine(); while (input != "Exit") { client.SendMessage(input);//到这里就报错了、 Console.WriteLine(); Console.Write("请输入:"); input = Console.ReadLine(); }