public void ServerAncClientEndpointBehavior() { var hook = new InvokesCounterBehaviour(); var address = @"net.pipe://127.0.0.1/test" + this.GetType().Name + "_" + MethodBase.GetCurrentMethod().Name; var serv = new Service(null); var host = new NDceRpc.ServiceModel.ServiceHost(serv, new Uri[] { new Uri(address), }); var b = new NDceRpc.ServiceModel.NetNamedPipeBinding(); var serverEndpoint = host.AddServiceEndpoint(typeof(IService), b, address); serverEndpoint.Behaviors.Add(hook); Assert.AreEqual(0, hook.Counter); host.Open(); Assert.AreEqual(1, hook.Counter); var f = new NDceRpc.ServiceModel.ChannelFactory <IService>(b); f.Endpoint.Behaviors.Add(hook); Assert.AreEqual(1, hook.Counter); var c = f.CreateChannel(new NDceRpc.ServiceModel.EndpointAddress(address)); Assert.AreEqual(2, hook.Counter); var result = c.DoWithParamsAndResult("", Guid.NewGuid()); host.Abort(); }
private static void DoWcfHost2Internal(Reportwatch reportWatch, Binding binding, string path) { reportWatch.Start("ServiceHost ctor"); using (var server = new ServiceHost(new Service2(), new Uri(path))) { reportWatch.Stop("ServiceHost ctor"); reportWatch.Start("AddServiceEndpoint"); server.AddServiceEndpoint(typeof(IService2), binding, path); reportWatch.Stop("AddServiceEndpoint"); reportWatch.Start("Open"); server.Open(); reportWatch.Stop("Open"); reportWatch.Start("ChannelFactory ctor"); using (var channelFactory = new NDceRpc.ServiceModel.ChannelFactory <IService2>(binding)) { reportWatch.Stop("ChannelFactory ctor"); reportWatch.Start("CreateChannel"); var client = channelFactory.CreateChannel(new EndpointAddress(path)); reportWatch.Stop("CreateChannel"); reportWatch.Start("Execute"); client.Execute2(new byte[0]); reportWatch.Stop("Execute"); } } }
public void TestTimeoutSet() { var uri = "net.pipe://127.0.0.1/testpipename" + MethodBase.GetCurrentMethod().Name; var binding = new NDceRpc.ServiceModel.NetNamedPipeBinding() { MaxConnections = 5 }; var timeout = 700; binding.ReceiveTimeout = TimeSpan.FromMilliseconds(timeout); var hang = TimeSpan.FromMilliseconds(timeout * 2); using (var server = new NDceRpc.ServiceModel.ServiceHost(new Service(), new Uri(uri))) { server.AddServiceEndpoint(typeof(IService), binding, uri); server.Open(); var channelFactory = new NDceRpc.ServiceModel.ChannelFactory <IService>(binding); var client = channelFactory.CreateChannel(new NDceRpc.ServiceModel.EndpointAddress(uri)); var result = client.Execute(TimeSpan.FromMilliseconds(0)); Assert.AreEqual(TimeSpan.FromMilliseconds(0), result); CommunicationException timeoutHappenedException = null; try { result = client.Execute(hang); } catch (CommunicationException ex) { timeoutHappenedException = ex; } Assert.NotNull(timeoutHappenedException); Assert.AreEqual(typeof(System.IO.IOException), timeoutHappenedException.InnerException.GetType()); var channel = client as NDceRpc.ServiceModel.IContextChannel; Assert.AreEqual(CommunicationState.Faulted, channel.State); try { result = client.Execute(TimeSpan.FromMilliseconds(0)); } catch (CommunicationObjectFaultedException afterTimeoutExeption) { } client = channelFactory.CreateChannel(new NDceRpc.ServiceModel.EndpointAddress(uri)); result = client.Execute(TimeSpan.FromMilliseconds(0)); } }
public void TestTimeoutSet() { var uri = "net.pipe://127.0.0.1/testpipename" + MethodBase.GetCurrentMethod().Name; var binding = new NDceRpc.ServiceModel.NetNamedPipeBinding() { MaxConnections = 5 }; var timeout = 700; binding.ReceiveTimeout = TimeSpan.FromMilliseconds(timeout); var hang = TimeSpan.FromMilliseconds(timeout * 2); using (var server = new NDceRpc.ServiceModel.ServiceHost(new Service(), new Uri(uri))) { server.AddServiceEndpoint(typeof(IService), binding, uri); server.Open(); var channelFactory = new NDceRpc.ServiceModel.ChannelFactory<IService>(binding); var client = channelFactory.CreateChannel(new NDceRpc.ServiceModel.EndpointAddress(uri)); var result = client.Execute(TimeSpan.FromMilliseconds(0)); Assert.AreEqual(TimeSpan.FromMilliseconds(0), result); CommunicationException timeoutHappenedException = null; try { result = client.Execute(hang); } catch (CommunicationException ex) { timeoutHappenedException = ex; } Assert.NotNull(timeoutHappenedException); Assert.AreEqual(typeof(System.IO.IOException), timeoutHappenedException.InnerException.GetType()); var channel = client as NDceRpc.ServiceModel.IContextChannel; Assert.AreEqual(CommunicationState.Faulted, channel.State); try { result = client.Execute(TimeSpan.FromMilliseconds(0)); } catch (CommunicationObjectFaultedException afterTimeoutExeption) { } client = channelFactory.CreateChannel(new NDceRpc.ServiceModel.EndpointAddress(uri)); result = client.Execute(TimeSpan.FromMilliseconds(0)); } }
public void Services_DifferentNamespaces_sameOperation() { var baseAddress = @"net.pipe://127.0.0.1/" + this.GetType().Name + MethodBase.GetCurrentMethod().Name; var serv = new ContractVersion1.Service(); using (var host = new NDceRpc.ServiceModel.ServiceHost(serv, new Uri[] { new Uri(baseAddress) })) { var binding = new NDceRpc.ServiceModel.NetNamedPipeBinding(); host.AddServiceEndpoint(typeof(ContractVersion1.IService), binding, baseAddress); host.Open(); using (var channelFatory = new NDceRpc.ServiceModel.ChannelFactory <ContractVersion2.IService>(binding)) { var c = channelFatory.CreateChannel(new NDceRpc.ServiceModel.EndpointAddress(baseAddress)); c.Do(); } } }
public void Services_autoAndManualIds_Ok() { var baseAddress = @"net.pipe://127.0.0.1/" + this.GetType().Name + MethodBase.GetCurrentMethod().Name; var serv = new ABCD(); using (var host = new NDceRpc.ServiceModel.ServiceHost(serv, new Uri[] { new Uri(baseAddress) })) { var binding = new NDceRpc.ServiceModel.NetNamedPipeBinding(); host.AddServiceEndpoint(typeof(IABCD), binding, baseAddress); host.Open(); using (var channelFatory = new NDceRpc.ServiceModel.ChannelFactory<IABCD>(binding)) { var c = channelFatory.CreateChannel(new NDceRpc.ServiceModel.EndpointAddress(baseAddress)); c.A(); c.D(); } } }
public void Services_autoAndManualIds_Ok() { var baseAddress = @"net.pipe://127.0.0.1/" + this.GetType().Name + MethodBase.GetCurrentMethod().Name; var serv = new ABCD(); using (var host = new NDceRpc.ServiceModel.ServiceHost(serv, new Uri[] { new Uri(baseAddress) })) { var binding = new NDceRpc.ServiceModel.NetNamedPipeBinding(); host.AddServiceEndpoint(typeof(IABCD), binding, baseAddress); host.Open(); using (var channelFatory = new NDceRpc.ServiceModel.ChannelFactory <IABCD>(binding)) { var c = channelFatory.CreateChannel(new NDceRpc.ServiceModel.EndpointAddress(baseAddress)); c.A(); c.D(); } } }
public void ServerAncClientEndpointBehavior() { var hook = new InvokesCounterBehaviour(); var address = @"net.pipe://127.0.0.1/test" + this.GetType().Name + "_" + MethodBase.GetCurrentMethod().Name; var serv = new Service(null); var host = new NDceRpc.ServiceModel.ServiceHost(serv, new Uri[] { new Uri(address), }); var b = new NDceRpc.ServiceModel.NetNamedPipeBinding(); var serverEndpoint = host.AddServiceEndpoint(typeof(IService), b, address); serverEndpoint.Behaviors.Add(hook); Assert.AreEqual(0, hook.Counter); host.Open(); Assert.AreEqual(1, hook.Counter); var f = new NDceRpc.ServiceModel.ChannelFactory<IService>(b); f.Endpoint.Behaviors.Add(hook); Assert.AreEqual(1, hook.Counter); var c = f.CreateChannel(new NDceRpc.ServiceModel.EndpointAddress(address)); Assert.AreEqual(2, hook.Counter); var result = c.DoWithParamsAndResult("", Guid.NewGuid()); host.Abort(); }
public void ServerAndClientExceptions() { var address = @"net.pipe://127.0.0.1/test" + this.GetType().Name + "_" + MethodBase.GetCurrentMethod().Name; var serv = new ExceptionService(); using (var host = new NDceRpc.ServiceModel.ServiceHost(serv, new Uri[] {new Uri(address),})) { var b = new NDceRpc.ServiceModel.NetNamedPipeBinding(); host.AddServiceEndpoint(typeof(IExceptionService), b, address); host.Open(); var f = new NDceRpc.ServiceModel.ChannelFactory<IExceptionService>(b); var c = f.CreateChannel(new NDceRpc.ServiceModel.EndpointAddress(address)); try { c.DoException("message"); } catch (Exception ex) { Assert.IsInstanceOf<NDceRpc.ServiceModel.FaultException>(ex); } host.Abort(); } }
public void ServerAndClientExceptions() { var address = @"net.pipe://127.0.0.1/test" + this.GetType().Name + "_" + MethodBase.GetCurrentMethod().Name; var serv = new ExceptionService(); using (var host = new NDceRpc.ServiceModel.ServiceHost(serv, new Uri[] { new Uri(address), })) { var b = new NDceRpc.ServiceModel.NetNamedPipeBinding(); host.AddServiceEndpoint(typeof(IExceptionService), b, address); host.Open(); var f = new NDceRpc.ServiceModel.ChannelFactory <IExceptionService>(b); var c = f.CreateChannel(new NDceRpc.ServiceModel.EndpointAddress(address)); try { c.DoException("message"); } catch (Exception ex) { Assert.IsInstanceOf <NDceRpc.ServiceModel.FaultException>(ex); } host.Abort(); } }
private static void DoWcfHost2Internal(Reportwatch reportWatch, Binding binding, string path) { reportWatch.Start("ServiceHost ctor"); using (var server = new ServiceHost(new Service2(), new Uri(path))) { reportWatch.Stop("ServiceHost ctor"); reportWatch.Start("AddServiceEndpoint"); server.AddServiceEndpoint(typeof(IService2), binding, path); reportWatch.Stop("AddServiceEndpoint"); reportWatch.Start("Open"); server.Open(); reportWatch.Stop("Open"); reportWatch.Start("ChannelFactory ctor"); using (var channelFactory = new NDceRpc.ServiceModel.ChannelFactory<IService2>(binding)) { reportWatch.Stop("ChannelFactory ctor"); reportWatch.Start("CreateChannel"); var client = channelFactory.CreateChannel(new EndpointAddress(path)); reportWatch.Stop("CreateChannel"); reportWatch.Start("Execute"); client.Execute2(new byte[0]); reportWatch.Stop("Execute"); } } }
public void Services_DifferentNamespaces_sameOperation() { var baseAddress = @"net.pipe://127.0.0.1/" + this.GetType().Name + MethodBase.GetCurrentMethod().Name; var serv = new ContractVersion1.Service(); using (var host = new NDceRpc.ServiceModel.ServiceHost(serv, new Uri[] { new Uri(baseAddress) })) { var binding = new NDceRpc.ServiceModel.NetNamedPipeBinding(); host.AddServiceEndpoint(typeof(ContractVersion1.IService), binding, baseAddress); host.Open(); using (var channelFatory = new NDceRpc.ServiceModel.ChannelFactory<ContractVersion2.IService>(binding)) { var c = channelFatory.CreateChannel(new NDceRpc.ServiceModel.EndpointAddress(baseAddress)); c.Do(); } } }