Exemplo n.º 1
0
        public void WfcServiceHost_LillTek_Via_Factory()
        {
            // Verify that we can create a service instance and then call it
            // using a client proxy generated by a WcfChannelFactory using
            // the LillTek transport.

            WcfServiceHost host;
            ITestService   client;

            host = new WcfServiceHost(new TestService());
            try
            {
                host.AddServiceEndpoint(typeof(ITestService), "binding=lilltek;uri=lilltek.logical://wcftest");
                host.ExposeServiceDescription(null, null);
                host.Start();

                using (WcfChannelFactory <ITestService> factory = new WcfChannelFactory <ITestService>("binding=lilltek;uri=lilltek.logical://wcftest"))
                {
                    client = factory.CreateChannel();
                    using (client as IDisposable)
                    {
                        client.Set("Hello World!");
                        Assert.AreEqual("Hello World!", client.Get());
                    }
                }
            }
            finally
            {
                host.Stop();
            }
        }
Exemplo n.º 2
0
        public void WfcServiceHost_Http_WcfClientContext()
        {
            // Verify that we can create a service instance and then call it using WcfClientContext.

            WcfServiceHost host;

            host = new WcfServiceHost(new TestService());
            try
            {
                host.AddServiceEndpoint(typeof(ITestService), @"binding=HTTP;uri=http://localhost:8008/Unit/Test.svc;settings=<wsHttpBinding><security mode=""None""/></wsHttpBinding>");
                host.ExposeServiceDescription(null, null);
                host.Start();

                using (WcfChannelFactory <ITestService> factory = new WcfChannelFactory <ITestService>(@"binding=HTTP;uri=http://localhost:8008/Unit/Test.svc;settings=<wsHttpBinding><security mode=""None""/></wsHttpBinding>"))
                    using (WcfClientContext <ITestService> client = new WcfClientContext <ITestService>(factory.CreateChannel()))
                    {
                        client.Open();
                        client.Proxy.Set("Hello World!");
                        Assert.AreEqual("Hello World!", client.Proxy.Get());
                    }
            }
            finally
            {
                host.Stop();
            }
        }
Exemplo n.º 3
0
        public void WfcServiceHost_Basic_Http_Via_Factory()
        {
            // Verify that we can create a service instance and then call it
            // using a client proxy generated by a WcfChannelFactory using
            // a HTTP transport.

            WcfServiceHost host;
            ITestService   client;

            host = new WcfServiceHost(new TestService());
            try
            {
                host.AddServiceEndpoint(typeof(ITestService), "binding=HTTP;uri=http://localhost:8008/Unit/Test.svc");
                host.ExposeServiceDescription(null, null);
                host.Start();

                using (WcfChannelFactory <ITestService> factory = new WcfChannelFactory <ITestService>("binding=HTTP;uri=http://localhost:8008/Unit/Test.svc"))
                {
                    client = factory.CreateChannel();
                    using (client as IDisposable)
                    {
                        client.Set("Hello World!");
                        Assert.AreEqual("Hello World!", client.Get());
                    }
                }
            }
            finally
            {
                host.Stop();
            }
        }
Exemplo n.º 4
0
        private static void SomeTesting()
        {
            var channelFactory  = new WcfChannelFactory <IApplicationService>(new NetTcpBinding());
            var endpointAddress = ConfigurationManager.AppSettings["prestoServiceAddress"];

            // The call to CreateChannel() actually returns a proxy that can intercept calls to the
            // service. This is done so that the proxy can retry on communication failures.
            IApplicationService appService = channelFactory.CreateChannel(new EndpointAddress(endpointAddress));

            Console.WriteLine("Enter some information to echo to the Presto service:");
            string message = Console.ReadLine();

            var          channelFactoryBase = new WcfChannelFactory <IBaseService>(new NetTcpBinding());
            IBaseService baseService        = channelFactoryBase.CreateChannel(new EndpointAddress(endpointAddress));
            string       returnMessage      = baseService.Echo(message);

            Console.WriteLine("Presto responds: {0}", returnMessage);

            IEnumerable <Application> apps = appService.GetAllApplications(true);

            foreach (var app in apps)
            {
                Console.WriteLine(app.Name);
            }
        }
Exemplo n.º 5
0
 private void Form1_Load(object sender, EventArgs e)
 {
     try
     {
         Test   test = new Test();
         string temp = test.DoWork();
         Func <GDIM_User, bool> conditions = delegate(GDIM_User user) { return(true); };
         string remoteAddress = ConfigHelper.GetSettingByName("RemoteServer");
         ITest  testSvc       = WcfChannelFactory.GetRemoteInstance <ITest>(BindingTypes.Basic, remoteAddress);
         string tempStr       = testSvc.DoWork();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Exemplo n.º 6
0
        /// <summary>
        /// Closes the connection if one has been established.
        /// </summary>
        public void Close()
        {
            lock (syncLock)
            {
                if (context != null)
                {
                    context.Close();
                    context = null;
                }

                remote = null;

                if (proxyFactory != null)
                {
                    proxyFactory.Dispose();
                    proxyFactory = null;
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Establishes a connection with the remote server manager, if a connection
        /// has not already been established.
        /// </summary>
        /// <exception cref="TimeoutException">Thrown if the remote instance did not respond.</exception>
        /// <exception cref="CommunicationException">Thrown if communication with the remote instance failed.</exception>
        /// <exception cref="SecurityException">Thrown if the credentials are invalid or if security policy forbids the operation.</exception>
        public void Open()
        {
            lock (syncLock)
            {
                if (proxyFactory != null)
                {
                    return;
                }

                proxyFactory = new WcfChannelFactory <IServerManager>(serverEP);
                context      = null;
                remote       = null;

                try
                {
                    context = new WcfClientContext <IServerManager>(proxyFactory.CreateChannel());
                    context.Open();

                    remote = context.Proxy;

                    Ping();
                }
                catch
                {
                    if (context != null)
                    {
                        context.Close();
                    }

                    remote = null;

                    proxyFactory.Close();
                    proxyFactory = null;

                    throw;
                }
            }
        }
 public WcfClientProxy(WcfChannelFactory <T> channelFactory) : base(typeof(T))
 {
     this._channelFactory = channelFactory;
 }