コード例 #1
0
        public void CallServiceReturningSession2TimesFor2Channels_sessionAreDifferentForDifferentChannels()
        {
            var address = @"net.pipe://127.0.0.1/1/test.test/test" + MethodBase.GetCurrentMethod().Name;

            var serv = new SessionService();
            var host = new ServiceHost(serv, new Uri(address));
            var b = new NetNamedPipeBinding();
            host.AddServiceEndpoint(typeof(ISessionService), b, address);
            var f1 = new ChannelFactory<ISessionService>(b);
            var f2 = new ChannelFactory<ISessionService>(b);
            var client1 = f1.CreateChannel(new EndpointAddress(address));
            var client2 = f2.CreateChannel(new EndpointAddress(address));
            host.Open();

            var session11 = client1.Call();
            var session21 = client2.Call();
            var session22 = client2.Call();
            var session12 = client1.Call();

            f1.Dispose();
            f2.Dispose();
            host.Dispose();
            Assert.AreEqual(session11, session12);
            Assert.AreEqual(session21, session22);
            Assert.AreNotEqual(session11, session21);
        }
コード例 #2
0
        public void ServerAncClientExceptionsEndpointBehavior()
        {
            var hook = new ExceptionsEndpointBehaviour();
            var address = @"net.pipe://127.0.0.1/test" + this.GetType().Name + "_" + MethodBase.GetCurrentMethod().Name;
            var serv = new ExceptionService();
            using (var host = new ServiceHost(serv, new Uri[] { new Uri(address), }))
            {
                var b = new NetNamedPipeBinding();
                var serverEndpoint = host.AddServiceEndpoint(typeof(IExceptionService), b, address);
                serverEndpoint.Behaviors.Add(hook);

                host.Open();

                var f = new ChannelFactory<IExceptionService>(b);
                f.Endpoint.Behaviors.Add(hook);

                var c = f.CreateChannel(new EndpointAddress(address));

                try
                {
                    c.DoException("message");
                }
                catch (InvalidOperationException ex)
                {
                    StringAssert.AreEqualIgnoringCase("message", ex.Message);
                }
                host.Abort();
            }
        }
コード例 #3
0
        public void CallServiceReturningSession2Times_sessionAreEqual()
        {
            var address = @"net.pipe://127.0.0.1/1/test.test/test" + MethodBase.GetCurrentMethod().Name;
            var binding = new NetNamedPipeBinding();

            var data = new CallbackData { Data = "1" };
            var srv = new CallbackService(data);
            var callback = new CallbackServiceCallback();

            using (var host = new ServiceHost(srv, new Uri(address)))
            {
                host.AddServiceEndpoint(typeof(ICallbackService), binding, address);
                host.Open();

                using (var factory = new DuplexChannelFactory<ICallbackService>(new InstanceContext(callback), binding))
                {
                    var client = factory.CreateChannel(new EndpointAddress(address));
                    client.Call();
                }

                callback.Wait.WaitOne();

                Assert.AreEqual(data.Data, callback.Called.Data);
            }
        }
コード例 #4
0
ファイル: AsyncTests.cs プロジェクト: OpenSharp/NDceRpc
        public void CallAsync_wait_done()
        {
            var address = @"net.pipe://127.0.0.1/" + this.GetType().Name + "_" + MethodBase.GetCurrentMethod().Name;
            var binding = new NetNamedPipeBinding();

            var done = new ManualResetEvent(false);
            var srv = new AsyncService(done);
            var callback = new AsyncServiceCallback();

            using (var host = new ServiceHost(srv, new Uri(address)))
            {
                host.AddServiceEndpoint(typeof(IAsyncService), binding, address);
                host.Open();

                ThreadPool.QueueUserWorkItem(_ =>
                {
                    using (var factory = new DuplexChannelFactory<IAsyncService>(new InstanceContext(callback), binding))
                    {
                        var client = factory.CreateChannel(new EndpointAddress(address));
                        AsyncCallback act = (x) =>
                        {
                            Assert.AreEqual(x.AsyncState, 1);
                        };
                        var result = client.BeginServiceAsyncMethod(act, 1);
                        result.AsyncWaitHandle.WaitOne();
                        Assert.AreEqual(result.AsyncState, 1);
                        client.EndServiceAsyncMethod(result);

                    }
                });

                done.WaitOne();
            }
        }
コード例 #5
0
        public void CallbackToSyncContext()
        {
            var path = @"net.pipe://127.0.0.1/" + this.GetType().Name + MethodBase.GetCurrentMethod().Name;
            var binding = new NetNamedPipeBinding() { MaxConnections = 5 };

            using (var server = new ServiceHost(new SyncCallbackService(), new Uri(path)))
            {

                server.AddServiceEndpoint(typeof(ISyncCallbackService), binding, path);

                server.Open();
                using (var syncContext = new StaSynchronizationContext())
                {
                    InstanceContext context = null;
                    NDceRpc.ServiceModel.DuplexChannelFactory<ISyncCallbackService> channelFactory = null;
                    ISyncCallbackService client = null;
                    syncContext.Send(_ => SynchronizationContext.SetSynchronizationContext(syncContext), null);
                    syncContext.Send(_ => context = new InstanceContext(new SyncCallbackServiceCallback()), null);
                    syncContext.Send(_ => channelFactory = new NDceRpc.ServiceModel.DuplexChannelFactory<ISyncCallbackService>(context, binding),null);
                    syncContext.Send(_ => client =  channelFactory.CreateChannel(new EndpointAddress(path)),null);
                    using (channelFactory)
                    {
                        var callbackThread = client.Call();
                        Assert.AreEqual(syncContext.ManagedThreadId, callbackThread);
                    }
                }

            }
        }
コード例 #6
0
ファイル: Voting.cs プロジェクト: sajjadahmadi/wcf-examples
 public static void MyClassInitialize(TestContext testContext)
 {
     binding = new NetNamedPipeBinding();
     host = new ServiceHost(typeof(MyService));
     host.AddServiceEndpoint(typeof(IChangeResource), binding, address);
     host.Open();
 }
コード例 #7
0
 public void FlowRequiredButNotEnabled()
 {
     ServiceHost<TestService2> host = new ServiceHost<TestService2>();
     NetNamedPipeBinding binding = new NetNamedPipeBinding();
     binding.TransactionFlow = false;  // default
     string address = "net.pipe://localhost/" + Guid.NewGuid().ToString();
     host.AddServiceEndpoint(typeof(ITestContract2), binding, address);
     host.Open();
 }
コード例 #8
0
 public void FlowRequiredAndEnabled()
 {
     using (ServiceHost<TestService2> host = new ServiceHost<TestService2>())
     {
         NetNamedPipeBinding binding = new NetNamedPipeBinding();
         binding.TransactionFlow = true;
         string address = "net.pipe://localhost/" + Guid.NewGuid().ToString();
         host.AddServiceEndpoint<ITestContract2>(binding, address);
         host.Open();
     }
 }
コード例 #9
0
ファイル: SDIntegration.cs プロジェクト: Antash/sda
        private void InitCommunicationService()
        {
            var host    = new ServiceHost(typeof(SDAService));
            var binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None)
            {
                ReceiveTimeout = TimeSpan.FromHours(42),
                SendTimeout    = TimeSpan.FromHours(42)
            };

            host.AddServiceEndpoint(typeof(ISDAService), binding, String.Format(CommunicationService.AddressTemplate, Program.AppGuid));
            host.Open();
        }
コード例 #10
0
        static void Main(string[] args)
        {
            var baseAddress = new Uri("net.pipe://localhost/WCFIssue");

            System.ServiceModel.ServiceHost serviceHost = new System.ServiceModel.ServiceHost(typeof(AdditionService), baseAddress);
            NetNamedPipeBinding             binding     = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None);

            serviceHost.AddServiceEndpoint(typeof(IAdditionService), binding, "AdditionService");
            serviceHost.Open();

            Console.WriteLine($"ServiceHost running at {baseAddress}. Press Return to Exit");
        }
コード例 #11
0
        public void RecentlyConnectedEndpointWithCommunicationFault()
        {
            var translator  = new Mock <ITranslateVersionedChannelInformation>();
            var translators = new[]
            {
                new Tuple <Version, ITranslateVersionedChannelInformation>(new Version(1, 0), translator.Object),
            };

            var configuration = new Mock <IConfiguration>();
            {
                configuration.Setup(c => c.HasValueFor(It.IsAny <ConfigurationKey>()))
                .Returns(false);
            }

            var template = new NamedPipeDiscoveryChannelTemplate(configuration.Object);
            Func <ChannelTemplate, IDiscoveryChannelTemplate> templateBuilder = t => template;
            var diagnostics = new SystemDiagnostics((l, s) => { }, null);
            var discovery   = new ManualDiscoverySource(
                translators,
                templateBuilder,
                diagnostics);

            discovery.OnEndpointBecomingAvailable += (s, e) => Assert.Fail();
            discovery.StartDiscovery();

            var uri      = new Uri("net.pipe://localhost/pipe/discovery");
            var receiver = new MockEndpoint(
                () =>
            {
                throw new ArgumentException();
            },
                null);

            var host    = new ServiceHost(receiver, uri);
            var binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None)
            {
                TransferMode = TransferMode.Buffered,
            };
            var address  = string.Format("{0}_{1}", "ThroughNamedPipe", Process.GetCurrentProcess().Id);
            var endpoint = host.AddServiceEndpoint(typeof(IBootstrapEndpoint), binding, address);

            host.Open();
            try
            {
                discovery.RecentlyConnectedEndpoint(
                    EndpointIdExtensions.CreateEndpointIdForCurrentProcess(),
                    endpoint.ListenUri);
            }
            finally
            {
                host.Close();
            }
        }
コード例 #12
0
ファイル: HandleBinding.cs プロジェクト: ewin66/XCYN
        public void Fun1()
        {
            var newNamedbinding  = new NetNamedPipeBinding();
            var nettcpBinding    = new NetTcpBinding();
            var wsHttpBinding    = new WSHttpBinding();
            var basicHttpBinding = new BasicHttpBinding();

            LookUpBinding(newNamedbinding);
            LookUpBinding(nettcpBinding);
            LookUpBinding(wsHttpBinding);
            LookUpBinding(basicHttpBinding);
        }
コード例 #13
0
        /* ----------------------------------------------------------------- */
        ///
        /// MessengerClient(T)
        ///
        /// <summary>
        /// オブジェクトを初期化します。
        /// </summary>
        ///
        /// <param name="id">識別子</param>
        ///
        /* ----------------------------------------------------------------- */
        public MessengerClient(string id)
        {
            var uri     = new Uri($"net.pipe://localhost/{id}");
            var address = new EndpointAddress(uri);
            var binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None);

            _callback = new MessengerServiceCallback <T>();
            _context  = new InstanceContext(_callback);
            _factory  = new DuplexChannelFactory <IMessengerService>(_callback, binding, address);

            Recreate();
        }
コード例 #14
0
ファイル: service.cs プロジェクト: mconnew/dotnet-api-docs
        static void SnippetReceiveSynchronously()
        {
            // <Snippet17>

            NetNamedPipeBinding        binding = new NetNamedPipeBinding();
            IBindingRuntimePreferences s       =
                binding.GetProperty <IBindingRuntimePreferences>
                    (new BindingParameterCollection());
            bool receiveSynchronously = s.ReceiveSynchronously;

            // </Snippet17>
        }
コード例 #15
0
        internal void ServiceHostThread()
        {
            try
            {
                Uri baseURI = new Uri(ConnectionFactory.GetAddress());
                var host    = new ServiceHost(this);

                NetNamedPipeBinding binding = ConnectionFactory.GetBinding();

                host.Faulted += _serviceHost_Faulted;

                /*
                 * Endpoints can be defined in the app.config file also.
                 * End points consist of an endpoint adress(baseURI), binding(named pipes in this case) and a service contract(this is the interface).
                 * A client must know the adress to connect to the service.
                 */
                var se = host.AddServiceEndpoint(
                    typeof(IServiceA),
                    binding,
                    baseURI);

                host.Open();

                Console.WriteLine("Service host thread started.");
                Console.WriteLine("Host binding: " + binding);
                Console.WriteLine("Host base URI: " + baseURI);
                int value = 0;
                while (!mExitNow)
                {
                    if (0 < mSleepTime)
                    {
                        Thread.Sleep(mSleepTime);
                        foreach (IServiceAEvents client in mCallbackList)
                        {
                            Console.WriteLine("Fire callback: " + value);
                            client.SendStatus(value);
                            value++;
                        }
                    }
                }

                host.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception caught trying to start service host thread...");
            }
            finally
            {
                Console.WriteLine("Service host thread exiting...");
            }
        }
コード例 #16
0
            /// <summary>
            /// Method used to check that any named pipe binding being used complies with a set of custom policies
            /// </summary>
            /// <param name="binding">The binding to check</param>
            public static void EnforceBindingPolicies(NetNamedPipeBinding binding)
            {
                if (binding.OpenTimeout > DefaultOpenTimeout)
                {
                    throw new Exception(string.Format(BrokenBindingPolicyMessage, "OpenTimeout"));
                }

                if (binding.CloseTimeout > DefaultCloseTimeout)
                {
                    throw new Exception(string.Format(BrokenBindingPolicyMessage, "CloseTimeout"));
                }

                if (binding.ReceiveTimeout > DefaultReceiveTimeout)
                {
                    throw new Exception(string.Format(BrokenBindingPolicyMessage, "ReceiveTimeout"));
                }

                if (binding.MaxBufferSize > DefaultMaxBufferSize)
                {
                    throw new Exception(string.Format(BrokenBindingPolicyMessage, "MaxBufferSize"));
                }

                if (binding.MaxReceivedMessageSize > DefaultMaxReceivedMessageSize)
                {
                    throw new Exception(string.Format(BrokenBindingPolicyMessage, "MaxReceivedMessageSize"));
                }

                if (binding.ReaderQuotas.MaxStringContentLength > DefaultMaxStringContentLength)
                {
                    throw new Exception(string.Format(BrokenBindingPolicyMessage, "MaxStringContentLength"));
                }

                if (binding.ReaderQuotas.MaxArrayLength > DefaultMaxArrayLength)
                {
                    throw new Exception(string.Format(BrokenBindingPolicyMessage, "MaxArrayLength"));
                }

                if (binding.ReaderQuotas.MaxBytesPerRead > DefaultMaxBytesPerRead)
                {
                    throw new Exception(string.Format(BrokenBindingPolicyMessage, "MaxBytesPerRead"));
                }

                if (binding.ReaderQuotas.MaxDepth > DefaultMaxDepth)
                {
                    throw new Exception(string.Format(BrokenBindingPolicyMessage, "MaxDepth"));
                }

                if (binding.ReaderQuotas.MaxNameTableCharCount > DefaultMaxNameTableCharCount)
                {
                    throw new Exception(string.Format(BrokenBindingPolicyMessage, "MaxNameTableCharCount"));
                }
            }
コード例 #17
0
        static void ValidateTransactionFlow(ServiceEndpoint endpoint)
        {
            Exception exception = new InvalidOperationException("BindingRequirementAttribute requires transaction flow enabled, but binding for the endpoint with contract " + endpoint.Contract.ContractType + " has it disabled");

            foreach (OperationDescription operation in endpoint.Contract.Operations)
            {
                TransactionFlowAttribute attribute = operation.Behaviors.Find <TransactionFlowAttribute>();
                if (attribute != null)
                {
                    if (attribute.Transactions == TransactionFlowOption.Allowed)
                    {
                        if (endpoint.Binding is NetTcpBinding)
                        {
                            NetTcpBinding tcpBinding = endpoint.Binding as NetTcpBinding;
                            if (tcpBinding.TransactionFlow == false)
                            {
                                throw exception;
                            }
                            continue;
                        }
                        if (endpoint.Binding is NetNamedPipeBinding)
                        {
                            NetNamedPipeBinding ipcBinding = endpoint.Binding as NetNamedPipeBinding;
                            if (ipcBinding.TransactionFlow == false)
                            {
                                throw exception;
                            }
                            continue;
                        }
                        if (endpoint.Binding is WSHttpBindingBase)
                        {
                            WSHttpBindingBase wsBinding = endpoint.Binding as WSHttpBindingBase;
                            if (wsBinding.TransactionFlow == false)
                            {
                                throw exception;
                            }
                            continue;
                        }
                        if (endpoint.Binding is WSDualHttpBinding)
                        {
                            WSDualHttpBinding wsDualBinding = endpoint.Binding as WSDualHttpBinding;
                            if (wsDualBinding.TransactionFlow == false)
                            {
                                throw exception;
                            }
                            continue;
                        }
                        throw new InvalidOperationException("BindingRequirementAttribute requires transaction flow enabled, but binding for the endpoint with contract " + endpoint.Contract.ContractType + " does not support transaction flow");
                    }
                }
            }
        }
コード例 #18
0
        internal static void StartProvider(Uri providerLocation, object provider, Type providerType)
        {
            if (s_runningProviders.ContainsKey(providerType))
            {
                return;
            }

            string sNamedPipe = providerLocation.ToString();
            // REVIEW: we don't dispose ServiceHost. It might be better to add it to the
            // SingletonsContainer
            ServiceHost providerHost = null;

            try
            {
                providerHost = new ServiceHost(provider);
                // Named pipes are better for Windows...don't tie up a dedicated port and perform better.
                // However, Mono does not yet support them, so on Mono we use a different binding.
                // Note that any attempt to unify these will require parallel changes in Paratext
                // and some sort of coordinated release of the new versions.
#if __MonoCS__
                BasicHttpBinding binding = new BasicHttpBinding();
#else
                NetNamedPipeBinding binding = new NetNamedPipeBinding();
                binding.Security.Mode = NetNamedPipeSecurityMode.None;
#endif
                binding.MaxBufferSize                       *= 4;
                binding.MaxReceivedMessageSize              *= 4;
                binding.MaxBufferPoolSize                   *= 2;
                binding.ReaderQuotas.MaxBytesPerRead        *= 4;
                binding.ReaderQuotas.MaxArrayLength         *= 4;
                binding.ReaderQuotas.MaxDepth               *= 4;
                binding.ReaderQuotas.MaxNameTableCharCount  *= 4;
                binding.ReaderQuotas.MaxStringContentLength *= 4;

                providerHost.AddServiceEndpoint(providerType, binding, sNamedPipe);
                providerHost.Open();
            }
            catch (Exception e)
            {
                Logger.WriteError(e);
                providerHost = null;
                var paratextInstalled = FwRegistryHelper.Paratext7orLaterInstalled();
                if (paratextInstalled)
                {
                    MessageBox.Show(PtCommunicationProb, PtCommunicationProbTitle,
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                return;
            }
            Logger.WriteEvent("Started provider " + providerLocation + " for type " + providerType + ".");
            s_runningProviders.Add(providerType, providerHost);
        }
コード例 #19
0
        public void InitializeChannel()
        {
            this.channelHandler = new ChannelHandler();
            this.channelHandler.OnMessageReceiveAndWaitAnserEvent = this.OnMessageReceiveAndWaitAnserEvent;

            this.serviceHost = new ServiceHost(this.channelHandler);

            this.binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None);
            this.binding.MaxBufferSize          = 2147483647;
            this.binding.MaxReceivedMessageSize = 2147483647;

            this.serviceHost.AddServiceEndpoint(typeof(IChannel), this.binding, this.channelAddress);
        }
コード例 #20
0
ファイル: MainWindow.xaml.cs プロジェクト: sin-us/sdhk
        public MainWindow()
        {
            string address = ControlPanelListener.Address;

            NetNamedPipeBinding binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None);
            EndpointAddress     ep      = new EndpointAddress(address);

            channel = ChannelFactory <IControlPanel> .CreateChannel(binding, ep);

            Debug.WriteLine("Client Connected");

            InitializeComponent();
        }
コード例 #21
0
        /// <summary>
        /// Creates and returns a new testing process communication channel.
        /// </summary>
        /// <param name="processId">Unique process id</param>
        /// <returns>ITestingProcess</returns>
        private ITestingProcess CreateTestingProcessChannel(uint processId)
        {
            Uri address = new Uri("net.pipe://localhost/psharp/testing/process/" +
                                  $"{processId}/{this.Configuration.TestingSchedulerEndPoint}");

            NetNamedPipeBinding binding = new NetNamedPipeBinding();

            binding.MaxReceivedMessageSize = Int32.MaxValue;

            EndpointAddress endpoint = new EndpointAddress(address);

            return(ChannelFactory <ITestingProcess> .CreateChannel(binding, endpoint));
        }
コード例 #22
0
        public ApplicationInstanceMonitor(string mutexName, string ipcUriPath)
        {
            this.mutexName = mutexName;
            var builder = new UriBuilder();

            builder.Scheme = Uri.UriSchemeNetPipe;
            builder.Host   = "localhost";
            builder.Path   = ipcUriPath;

            this.ipcUri = builder.Uri;

            this.binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.Transport);
        }
コード例 #23
0
        /* ----------------------------------------------------------------- */
        ///
        /// MessengerServer
        ///
        /// <summary>
        /// オブジェクトを初期化します。
        /// </summary>
        ///
        /// <param name="id">識別子</param>
        ///
        /* ----------------------------------------------------------------- */
        public MessengerServer(string id)
        {
            _dispose = new OnceAction <bool>(Dispose);

            var address = new Uri($"net.pipe://localhost/{id}");
            var binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None);

            _service = new MessengerService <TValue>();

            _host = new ServiceHost(_service);
            _host.AddServiceEndpoint(typeof(IMessengerService), binding, address);
            _host.Open();
        }
コード例 #24
0
        private static Binding GetMemoryTypeBinding()
        {
            var binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None)
            {
                MaxReceivedMessageSize = int.MaxValue,
                ReceiveTimeout         = TimeSpan.MaxValue,
                SendTimeout            = NetworkTimeout,
                OpenTimeout            = NetworkTimeout,
                CloseTimeout           = NetworkTimeout
            };

            return(binding);
        }
コード例 #25
0
        static Binding CreateRegisterBinding(TransportType transportType)
        {
            NetNamedPipeBinding binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None);

            binding.MaxReceivedMessageSize = ListenerConstants.RegistrationMaxReceivedMessageSize;
            CustomBinding customBinding = new CustomBinding(binding);
            NamedPipeTransportBindingElement namedPipeBindingElement = customBinding.Elements.Find <NamedPipeTransportBindingElement>();

            namedPipeBindingElement.ExposeConnectionProperty = true;
            namedPipeBindingElement.AllowedUsers             = ListenerConfig.GetAllowAccounts(transportType);
            customBinding.ReceiveTimeout = TimeSpan.MaxValue;
            return(customBinding);
        }
コード例 #26
0
        private void btnMakeCall_Click(object sender, RoutedEventArgs e)
        {
            Binding         binding = new NetNamedPipeBinding();
            EndpointAddress address = new EndpointAddress("net.pipe://localhost/MessageService");

            //ChannelFactory<IMessageService> factory = new ChannelFactory<IMessageService>("");
            ChannelFactory <IMessageService> factory =
                new ChannelFactory <IMessageService>(binding, address);
            IMessageService proxy = factory.CreateChannel();

            proxy.ShowMsg(txtMessage.Text);
            factory.Close();
        }
コード例 #27
0
        public string Inspect(ManagedApplicationInfo applicationInfo)
        {
#if NETCORE
            var binding        = new NetTcpBinding();
            var channelFactory = new ChannelFactory <IProcessService>(binding, new EndpointAddress(ProcessServiceAddress));
#else
            var binding        = new NetNamedPipeBinding();
            var channelFactory = new ChannelFactory <IProcessService>(binding, ProcessServiceNet35Address);
#endif

            IProcessService processService = channelFactory.CreateChannel();
            return(processService.Inspect(applicationInfo));
        }
コード例 #28
0
ファイル: ClientService.cs プロジェクト: rootn3rd/ipc
        public void ConnectToChannel(string clientName)
        {
            _clientName = clientName;

            string address = Constants.EndPointAddress;

            NetNamedPipeBinding binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None);
            EndpointAddress     ep      = new EndpointAddress(address);

            _connection = ChannelFactory <IMaster> .CreateChannel(binding, ep);

            Console.WriteLine("Client Connected");
        }
コード例 #29
0
        public void Open_Open_error()
        {
            var address = @"net.pipe://127.0.0.1/" + this.GetType().Name + MethodBase.GetCurrentMethod().Name;
            var serv    = new Service(null);

            using (var host = new ServiceHost(serv, new Uri[] { new Uri(address) }))
            {
                var b = new NetNamedPipeBinding();
                host.AddServiceEndpoint(typeof(IService), b, address);
                host.Open();
                host.Open();
            }
        }
コード例 #30
0
        public void Update()
        {
            using (ServiceHost host = new ServiceHost(typeof(PathControllerActions), new Uri("net.pipe://localhost")))
            {
                NetNamedPipeBinding netNamedPipeBinding = new NetNamedPipeBinding();

                host.AddServiceEndpoint(typeof(IPathControllerActions), new NetNamedPipeBinding(), "pathController/" + id.ToString());
                host.Open();
                Console.WriteLine("Press any key to exit.");
                Console.ReadKey();
                host.Close();
            }
        }
コード例 #31
0
ファイル: Program.cs プロジェクト: stevosaurus/wcfissue
        static void Main(string[] args)
        {
            var connectionAddress = "net.pipe://localhost/DummyEndPoint";
            var binding           = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None);
            var ep = new EndpointAddress(connectionAddress);

            var additionService = ChannelFactory <IAdditionService> .CreateChannel(binding, ep, new Uri(connectionAddress));

            var additionResult = additionService.Add(1, 2);

            Console.WriteLine($"Results from adding 1 and 2: {additionResult}");
            Console.ReadLine();
        }
コード例 #32
0
        /// <summary>
        /// Creates the WCF Service Host which is accessible via named pipes.
        /// </summary>
        private void OpenNamedPipeServiceHost()
        {
            if (null != this.namedPipeServiceHost)
            {
                this.namedPipeServiceHost.Close();
            }
            this.namedPipeServiceHost          = new ServiceHost(typeof(AdminGroupManipulator), new Uri(Settings.NamedPipeServiceBaseAddress));
            this.namedPipeServiceHost.Faulted += ServiceHostFaulted;
            NetNamedPipeBinding binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.Transport);

            this.namedPipeServiceHost.AddServiceEndpoint(typeof(IAdminGroup), binding, Settings.NamedPipeServiceBaseAddress);
            this.namedPipeServiceHost.Open();
        }
コード例 #33
0
        static void Main(string[] args)
        {
            string address = "net.pipe://localhost/selector/12345";

            NetNamedPipeBinding binding     = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None);
            ServiceHost         serviceHost = new ServiceHost(typeof(TestServer.TestServer));

            serviceHost.AddServiceEndpoint(typeof(TestServer.ITestContract), binding, address);
            serviceHost.Open();

            Console.WriteLine("ServiceHost running. Press Return to Exit");
            Console.ReadLine();
        }
コード例 #34
0
        public void Run()
        {
            var address = new Uri("net.pipe://localhost/fleetdaemon");
            var binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None);

            this.service = new ServiceHost(typeof(DaemonService));
            this.service.AddServiceEndpoint(typeof(IDaemonIPC), binding, address);
            this.service.Open();
            Console.WriteLine("Daemon running. Press the any key to exit.");
            Console.WriteLine(Directory.GetCurrentDirectory());

            Process.Start(@"..\..\..\FileShare\bin\Debug\FileShare.exe");
        }
コード例 #35
0
        internal static void ConfigureNone(Collection <ServiceEndpoint> endpoints)
        {
            foreach (ServiceEndpoint endpoint in endpoints)
            {
                Binding binding = endpoint.Binding;

                if (binding is BasicHttpBinding)
                {
                    BasicHttpBinding basicBinding = (BasicHttpBinding)binding;
                    basicBinding.Security.Mode = BasicHttpSecurityMode.None;
                    continue;
                }
                if (binding is NetTcpBinding)
                {
                    NetTcpBinding tcpBinding = (NetTcpBinding)binding;
                    tcpBinding.Security.Mode = SecurityMode.None;
                    continue;
                }
                if (binding is NetPeerTcpBinding)
                {
                    NetPeerTcpBinding peerBinding = (NetPeerTcpBinding)binding;
                    peerBinding.Security.Mode = SecurityMode.None;
                    continue;
                }
                if (binding is NetNamedPipeBinding)
                {
                    NetNamedPipeBinding pipeBinding = (NetNamedPipeBinding)binding;
                    pipeBinding.Security.Mode = NetNamedPipeSecurityMode.None;
                    continue;
                }
                if (binding is WSHttpBinding)
                {
                    WSHttpBinding wsBinding = (WSHttpBinding)binding;
                    wsBinding.Security.Mode = SecurityMode.None;
                    continue;
                }
                if (binding is WSDualHttpBinding)
                {
                    WSDualHttpBinding wsDualBinding = (WSDualHttpBinding)binding;
                    wsDualBinding.Security.Mode = WSDualHttpSecurityMode.None;
                    continue;
                }
                if (binding is NetMsmqBinding)
                {
                    NetMsmqBinding msmqBinding = (NetMsmqBinding)binding;
                    msmqBinding.Security.Mode = NetMsmqSecurityMode.None;
                    continue;
                }
                throw new InvalidOperationException(binding.GetType() + "is unsupprted with ServiceSecurity.None");
            }
        }
コード例 #36
0
        private void StartProcess()
        {
            // If we already have a reference to the child
            if (_process != null && !_process.HasExited)
            {
                return;
            }

            // Unhook old process
            UnhookProcessEvent();

            // Get exe
            string loc = typeof(LowRights.Program).Assembly.Location;

            string id = Assembly.GetEntryAssembly().EscapedCodeBase;


            //string args = string.Format("{0} {1} {2}", id, timeOutSec, "DEBUG");
            string args = string.Format(CultureInfo.InvariantCulture, "{0} {1}", id, TimeOutSeconds);



            // To use the regular way of starting a process use this insead of StartLowIntegrityProcess

            //ProcessStartInfo info = new ProcessStartInfo(loc, id + " DEBUG");
            //ProcessStartInfo info = new ProcessStartInfo(loc, id);
            //info.UseShellExecute = false;
            //_process = Process.Start(info);

            _process = LowIntegrityProcess.Start(loc, args);
            if (!_process.HasExited)
            {
                _process.EnableRaisingEvents = true;
                _process.Exited += ChildExited;
            }
            else
            {
                _process = null;
            }

            string uri = string.Format(Program.Address, id) + "/CookieService";

            NetNamedPipeBinding             binding = new NetNamedPipeBinding();
            ChannelFactory <ICookieService> factory = new ChannelFactory <ICookieService>(binding, uri);

            _service = factory.CreateChannel();

            // Allow the other side to setup the pipe -- ideally this should be synchronized instead of
            // a blanket sleep
            Thread.Sleep(1000);
        }
コード例 #37
0
        public static Binding CreateBindingFromScheme(Uri uri, TransferMode transferMode)
        {
            Guard.ArgumentNotNull("uri", uri);

            switch (uri.Scheme.ToLower())
            {
            case "net.tcp":
                var netTcp = new NetTcpBinding(SecurityMode.None);
                netTcp.MaxReceivedMessageSize = int.MaxValue;
                netTcp.ReaderQuotas.MaxStringContentLength = int.MaxValue;
                netTcp.ReaderQuotas.MaxArrayLength         = int.MaxValue;
                netTcp.SendTimeout  = MessageSentTimeout;
                netTcp.TransferMode = transferMode;
                return(netTcp);

            //                service can't call application wcf service thought net.pipe on vista
            //                see http://blogs.thinktecture.com/cweyer/archive/2007/12/07/415050.aspx for details
            case "net.pipe":
                var netPipe = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None);
                netPipe.MaxReceivedMessageSize = int.MaxValue;
                netPipe.ReaderQuotas.MaxStringContentLength = int.MaxValue;
                netPipe.ReaderQuotas.MaxArrayLength         = int.MaxValue;
                netPipe.SendTimeout  = MessageSentTimeout;
                netPipe.TransferMode = transferMode;
                return(netPipe);

            case "http":
                var http = new BasicHttpBinding();
                http.MaxReceivedMessageSize = int.MaxValue;
                http.ReaderQuotas.MaxStringContentLength = int.MaxValue;
                http.ReaderQuotas.MaxArrayLength         = int.MaxValue;
                http.SendTimeout  = MessageSentTimeout;
                http.TransferMode = transferMode;

                return(http);

            case "https":
                var https = new BasicHttpBinding();
                https.MaxReceivedMessageSize = int.MaxValue;
                https.ReaderQuotas.MaxStringContentLength = int.MaxValue;
                https.ReaderQuotas.MaxArrayLength         = int.MaxValue;
                https.SendTimeout   = MessageSentTimeout;
                https.TransferMode  = transferMode;
                https.Security.Mode = BasicHttpSecurityMode.Transport;
                https.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.Certificate;

                return(https);

            default: throw new InvalidOperationException();
            }
        }
コード例 #38
0
ファイル: Helper.cs プロジェクト: tavaratv/novaroma
        public static IShellService CreateShellServiceClient(TimeSpan timeout)
        {
            var binding = new NetNamedPipeBinding {
                OpenTimeout            = timeout,
                MaxReceivedMessageSize = 20000000,
                MaxBufferPoolSize      = 20000000,
                MaxBufferSize          = 20000000
            };
            const string endpointAddress = Constants.NetPipeUri + Constants.NetPipeEndpointName;
            var          endpoint        = new EndpointAddress(endpointAddress);
            var          channelFactory  = new ChannelFactory <IShellService>(binding, endpoint);

            return(channelFactory.CreateChannel());
        }
コード例 #39
0
ファイル: ChannelTests.cs プロジェクト: OpenSharp/NDceRpc
        public void InvokenBlockingWithParams_resultObtained()
        {
            var address = @"net.pipe://127.0.0.1/1/test.test/test";

            var serv = new Service(null);
            var host = new ServiceHost(serv, new Uri(address));
            var b = new NetNamedPipeBinding();
            host.AddServiceEndpoint(typeof(IService), b, address);
            host.Open();
            var f = new ChannelFactory<IService>(b);
            var c = f.CreateChannel(new EndpointAddress(address));
            var result = c.DoWithParamsAndResult(":)", Guid.NewGuid());
            Assert.AreEqual(2, result.d1);
            host.Dispose();
        }
コード例 #40
0
ファイル: AsyncTests.cs プロジェクト: OpenSharp/NDceRpc
        public void CallAsync_noServer_done()
        {
            var address = @"net.pipe://127.0.0.1/" + this.GetType().Name + "_" + MethodBase.GetCurrentMethod().Name;
            var binding = new NetNamedPipeBinding();

            var callback = new AsyncServiceCallback();

            using (var factory = new DuplexChannelFactory<IAsyncService>(new InstanceContext(callback), binding))
            {
                var client = factory.CreateChannel(new EndpointAddress(address));
                AsyncCallback act = x => Assert.AreEqual(x.AsyncState, 1);
                IAsyncResult result = client.BeginServiceAsyncMethod(act, 1);
                result.AsyncWaitHandle.WaitOne();
                Assert.AreEqual(result.AsyncState, 1);
            }
        }
コード例 #41
0
ファイル: ChannelTests.cs プロジェクト: OpenSharp/NDceRpc
        public void DisposedChannelFactory_call()
        {
            var address = @"net.pipe://127.0.0.1/" + Guid.NewGuid().ToString("N");
            var serv = new SimpleService();
            var b = new NetNamedPipeBinding();

            using (var host = new ServiceHost(serv, new Uri[] { new Uri(address), }))
            {
                host.AddServiceEndpoint(typeof(ISimpleService), b, address);
                host.Open();
                var f = new ChannelFactory<ISimpleService>(b);
                var c = f.CreateChannel(new EndpointAddress(address));
                using (f) { }
                c.Do();
            }
        }
コード例 #42
0
        public void ReleaseInstanceModeBeforeTest()
        {
            Binding binding = new NetNamedPipeBinding();
            var address = "net.pipe://localhost/" + Guid.NewGuid();
            using (var host =
                new ServiceHost(typeof(MyService), new Uri(address)))
            {
                host.AddServiceEndpoint(typeof(IMyCounter), binding, "");
                host.Open();

                var proxy = ChannelFactory<IMyCounter>.CreateChannel(binding, new EndpointAddress(address));
                proxy.SetCount(3);
                Assert.AreEqual(3, proxy.GetCount());
                Assert.AreEqual(1, proxy.ReleaseBeforeIncrement());
                Assert.AreEqual(1, proxy.GetCount());
                ((ICommunicationObject)proxy).Close();
            }
        }
コード例 #43
0
ファイル: HostTests.cs プロジェクト: OpenSharp/NDceRpc
        public void Open_2Endpoints_callsBoth()
        {
            var baseAddress = @"net.pipe://127.0.0.1/" + this.GetType().Name + MethodBase.GetCurrentMethod().Name;
            var serv = new Service(null);
            using (var host = new ServiceHost(serv, new Uri[] { new Uri(baseAddress) }))
            {
                var binding = new NetNamedPipeBinding();
                host.AddServiceEndpoint(typeof(IService), binding, baseAddress + "/1");
                host.AddServiceEndpoint(typeof(IService), binding, baseAddress + "/2");
                host.Open();
                using (var channelFatory = new ChannelFactory<IService>(binding))
                {
                    var c1 = channelFatory.CreateChannel(new EndpointAddress(baseAddress + "/1"));
                    var c2 = channelFatory.CreateChannel(new EndpointAddress(baseAddress + "/2"));
                    c1.DoWithParamsAndResult("", Guid.Empty);
                    c2.DoWithParamsAndResult("", Guid.Empty);
                }

            }
        }
コード例 #44
0
ファイル: AsyncTests.cs プロジェクト: OpenSharp/NDceRpc
        public void CallbackAsyncCallback_wait_done()
        {
            var address = @"net.pipe://127.0.0.1/" + this.GetType().Name + "_" + MethodBase.GetCurrentMethod().Name;
            var binding = new NetNamedPipeBinding();

            var srv = new AsyncService(null);
            var callback = new AsyncServiceCallback();

            using (var host = new ServiceHost(srv, new Uri(address)))
            {
                host.AddServiceEndpoint(typeof(IAsyncService), binding, address);
                host.Open();

                using (var factory = new DuplexChannelFactory<IAsyncService>(new InstanceContext(callback), binding))
                {
                    var client = factory.CreateChannel(new EndpointAddress(address));
                    client.DoSyncCall();

                }
            }
        }
コード例 #45
0
ファイル: ChannelTests.cs プロジェクト: OpenSharp/NDceRpc
        public void IContextChannel_operationTimeoutSetGet_Ok()
        {
            var address = @"net.pipe://127.0.0.1/" + this.GetType().Name + "_" + MethodBase.GetCurrentMethod().Name;
            var binding = new NetNamedPipeBinding();
            using (var server = new ServiceHost(new SimpleService(), new Uri(address)))
            {

                server.AddServiceEndpoint(typeof(ISimpleService), binding, address);
                server.Open();
                Thread.Sleep(100);
                using (var channelFactory = new ChannelFactory<ISimpleService>(binding))
                {
                    var client = channelFactory.CreateChannel(new EndpointAddress(address));
                    var contextChannel = client as IContextChannel;
                    var newTimeout = TimeSpan.FromSeconds(123);
                    contextChannel.OperationTimeout = newTimeout;
                    var timeout = contextChannel.OperationTimeout;
                    Assert.AreEqual(newTimeout, timeout);

                }
            }
        }
コード例 #46
0
        public void TestSetThrottle()
        {
            NetNamedPipeBinding binding = new NetNamedPipeBinding();
            string address = "net.pipe://localhost/" + Guid.NewGuid().ToString();

            using (ServiceHost<ThrottledService> host = new ServiceHost<ThrottledService>(address)) {
                host.AddServiceEndpoint<IThrottlingInformation>(binding, "");
                host.SetThrottle(12, 34, 56);
                host.Open();

                IThrottlingInformation service = ChannelFactory<IThrottlingInformation>.CreateChannel(
                    binding,
                    new EndpointAddress(address));

                using (service as IDisposable) {
                    ThrottleInfo info = service.GetThrottleInfo();
                    Assert.AreEqual(12, info.MaxConcurrentCalls);
                    Assert.AreEqual(34, info.MaxConcurrentSessions);
                    Assert.AreEqual(56, info.MaxConcurrentInstances);
                }
            }
        }
コード例 #47
0
ファイル: ChannelTests.cs プロジェクト: OpenSharp/NDceRpc
 public void InvokeOneWay_waitOnEvent_received()
 {
     var address = @"net.pipe://127.0.0.1/1/test.test/test";
     var wait = new ManualResetEvent(false);
     var serv = new Service(wait);
     var host = new ServiceHost(serv, new Uri(address));
     var b = new NetNamedPipeBinding();
     host.AddServiceEndpoint(typeof(IService), b, address);
     var f = new ChannelFactory<IService>(b);
     var c = f.CreateChannel(new EndpointAddress(address));
     host.Open();
     c.DoOneWay();
     wait.WaitOne();
     host.Dispose();
 }
コード例 #48
0
ファイル: ChannelTests.cs プロジェクト: OpenSharp/NDceRpc
        public void LongNamePipe()
        {
            var address = @"net.pipe://127.0.0.1/1/test.test/testtestLongNameLongNameLongNameLongNameLongNameLongNameLongNameLongNameLongNamefd0286a60b9b4db18659-b715e5db5b3bd0286a6-0b9b-4db1-8659-b715e5db5b3b";
            var serv = new Service(null);
            var host = new ServiceHost(serv, new Uri(address));
            var b = new NetNamedPipeBinding();
            host.AddServiceEndpoint(typeof(IService), b, address);
            host.Open();
            var f = new ChannelFactory<IService>(b);
            var c = f.CreateChannel(new EndpointAddress(address));

            var result = c.DoWithParamsAndResult(":)", Guid.NewGuid());
            Assert.AreEqual(2, result.d1);
            host.Dispose();
        }
コード例 #49
0
ファイル: ChannelTests.cs プロジェクト: OpenSharp/NDceRpc
        public void InvokeOtherService()
        {
            var address = @"net.pipe://127.0.0.1/1/test.test/test" + MethodBase.GetCurrentMethod().Name;
            var otherAddress = @"net.pipe://127.0.0.1/1/test.test/other" + MethodBase.GetCurrentMethod().Name;
            var wait = new ManualResetEvent(false);
            var srv = new Service(null);
            var otherSrv = new OtherService(wait);
            var host = new ServiceHost(srv, new Uri(address));
            var b = new NetNamedPipeBinding();
            host.AddServiceEndpoint(typeof(IService), b, address);
            var otherHost = new ServiceHost(otherSrv, new Uri(address));

            otherHost.AddServiceEndpoint(typeof(IOtherService), b, otherAddress);
            var f = new ChannelFactory<IService>(b);
            var c = f.CreateChannel(new EndpointAddress(address));

            host.Open();
            otherHost.Open();
            c.CallOtherService(otherAddress);
            wait.WaitOne();
            host.Dispose();
            otherHost.Dispose();
        }
コード例 #50
0
ファイル: AsyncTests.cs プロジェクト: OpenSharp/NDceRpc
        public void CallTask_wait_done()
        {
            var address = @"net.pipe://127.0.0.1/" + this.GetType().Name + "_" + MethodBase.GetCurrentMethod().Name;
            var binding = new NetNamedPipeBinding();

            var srv = new AsyncTaskService();

            using (var host = new ServiceHost(srv, new Uri(address)))
            {
                host.AddServiceEndpoint(typeof(IAsyncTaskService), binding, address);
                host.Open();

                var done = Task.Factory.StartNew(() =>
                {
                    using (var factory = new ChannelFactory<IAsyncTaskService>(binding))
                    {
                        var client = factory.CreateChannel(new EndpointAddress(address));
                        var result = client.GetMessages("123");
                        result.Wait();
                        Assert.AreEqual(result.Result, "321");
                    }
                });
                done.Wait();
            }
        }
コード例 #51
0
ファイル: PerformanceTests.cs プロジェクト: OpenSharp/NDceRpc
        public void NamedPipe_byteArray()
        {
            using (var server = new ServiceHost(new Service(), new Uri("net.pipe://127.0.0.1/testpipename")))
            {
                var binding = new NetNamedPipeBinding { MaxConnections = 5 };
                server.AddServiceEndpoint(typeof(IService), binding, "net.pipe://127.0.0.1/testpipename");
                server.Open();
                Thread.Sleep(100);
                using (var channelFactory = new ChannelFactory<IService>(binding))
                {

                    var client = channelFactory.CreateChannel(new EndpointAddress("net.pipe://127.0.0.1/testpipename"));
                    client.Execute(new byte[0]);

                    byte[] bytes = new byte[512];
                    new Random().NextBytes(bytes);

                    var timer = new Stopwatch();
                    timer.Start();

                    for (int i = 0; i < 5000; i++)
                        client.Execute(bytes);

                    timer.Stop();
                    Trace.WriteLine(timer.ElapsedMilliseconds.ToString() + " ms", MethodBase.GetCurrentMethod().Name);
                }
            }
        }