zoukankan      html  css  js  c++  java
  • wcf

    [ServiceContract()]
    interface IMyService
    {
        [OperationContract()]
        void DoSomething();
    }

    public class MyService : IMyService
    {
        public void DoSomething()
        {
            // do something
        }
    }

    原方

    public class Test
    {
        public void Test()
        {
            BasicHttpBinding myBinding = new BasicHttpBinding();
            EndpointAddress myEndpoint = new EndpointAddress("http://localhost/MyService/");
            ChannelFactory<imyservice> myChannelFactory = new ChannelFactory<imyservice>(myBinding, myEndpoint);
            IMyService pClient = myChannelFactory.CreateChannel();
            pClient.DoSomething();
            ((IClientChannel)pClient).Close();
        }
    }

    =====

    public class Test
    {
        public void Test()
        {
            //create client proxy from factory
            IMyService pClient = (IMyService)ClientFactory.CreateClient(typeof(IMyService));
            pClient.DoSomething();
            ((IClientChannel)pClient).Close();
        }
    }
    //Factory class for client proxy
    public abstract class ClientFactory
    {
        public static object CreateClient(Type targetType)
        {
            BasicHttpBinding binding = new BasicHttpBinding();
            //Get the address of the service from configuration or some other mechanism - Not shown here
            EndpointAddress addess = new EndpointAddress(GetAddessFromConfig(targetType));
            //dynamic factory generation
            object factory = Activator.CreateInstance(typeof
            (ChannelFactory<>).MakeGenericType(targetType), binding, address);
            MethodInfo createFactory = factory.GetType().GetMethod("CreateChannel", new Type[] { });
            //now dynamic proxy generation using reflection
            return createFactory.Invoke(factory, null);
        }
    }

  • 相关阅读:
    samba安装和配置
    linux下打包命令的使用
    Linux目录结构简析
    Linux服务器的安装
    linux下定时任务设置
    创建表空间并授权
    selenium2.0(WebDriver) API
    selenium + python之元素定位
    Linux实战教学笔记13:定时任务补充
    Linux实战教学笔记11:linux定时任务
  • 原文地址:https://www.cnblogs.com/zeroone/p/3659705.html
Copyright © 2011-2022 走看看