program.cs

来自「C#高级编程第6版随书源代码 值得下载」· CS 代码 · 共 45 行

CS
45
字号
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;

namespace Wrox.ProCSharp.WCF
{
   class ClientCallback : IMyMessageCallback
   {
      public void OnCallback(string message)
      {
         Console.WriteLine("message from the server: {0}", message);
      }
   }


   class Program
   {
      static void Main()
      {
         Console.WriteLine("Client - wait for service");
         Console.ReadLine();

         WSDualHttpBinding binding = new WSDualHttpBinding();
         EndpointAddress address =
               new EndpointAddress("http://localhost:8731/Design_Time_Addresses/MessageService/Service1/");

         ClientCallback clientCallback = new ClientCallback();
         InstanceContext context = new InstanceContext(clientCallback);

         DuplexChannelFactory<IMyMessage> factory =
            new DuplexChannelFactory<IMyMessage>(context, binding, address);

         IMyMessage messageChannel = factory.CreateChannel();

         messageChannel.MessageToServer("From the client");

         Console.WriteLine("Client - press return to exit");
         Console.ReadLine();

      }
   }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?