void CheckEchoDoesNotReturnNullCallback(IEcho client) { var cid = client.Echo("hi"); Assert.IsNotNull(cid); Guid guid; Assert.IsTrue(Guid.TryParse(cid, out guid)); }
static void Main(string[] args) { IEcho toWrap = new EchoImpl(); IEcho decorator = DispatchProxy.Create <IEcho, GenericDecorator>(); ((GenericDecorator)decorator).Wrapped = toWrap; ((GenericDecorator)decorator).Start = (tm, a) => Console.WriteLine($"{tm.Name}({string.Join(',', a)}) is started"); ((GenericDecorator)decorator).End = (tm, a, r) => Console.WriteLine($"{tm.Name}({string.Join(',', a)}) is ended with result {r}"); string result = decorator.Echo("Hello"); }
static void Main() { ServiceHost serviceHost = null; ChannelFactory <IEcho> echoChannelFactory = null; WSTrustServiceHost securityTokenServiceHost = null; try { // // Start the service // serviceHost = new ServiceHost(typeof(EchoService)); string serviceAddress = "http://localhost:8080/EchoService"; serviceHost.AddServiceEndpoint(typeof(IEcho), GetServiceBinding(), serviceAddress); ServiceMetadataBehavior metadataBehavior = new ServiceMetadataBehavior(); metadataBehavior.HttpGetEnabled = true; metadataBehavior.HttpGetUrl = new Uri(serviceAddress); serviceHost.Description.Behaviors.Add(metadataBehavior); serviceHost.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexHttpBinding(), serviceAddress + "/mex"); serviceHost.Credentials.ServiceCertificate.SetCertificate("CN=localhost", StoreLocation.LocalMachine, StoreName.My); serviceHost.Open(); Console.WriteLine("The echo service has started at {0}.\n", serviceAddress); // // Start the STS // SecurityTokenServiceConfiguration securityTokenServiceConfiguration = new SecurityTokenServiceConfiguration(securityTokenServiceAddress, new X509SigningCredentials(serviceHost.Credentials.ServiceCertificate.Certificate)); securityTokenServiceConfiguration.WSTrust13RequestSerializer = new CustomWSTrust13RequestSerializer(); securityTokenServiceConfiguration.SecurityTokenService = typeof(CustomSecurityTokenService); // Add the STS endpoint information securityTokenServiceConfiguration.TrustEndpoints.Add( new ServiceHostEndpointConfiguration(typeof(IWSTrust13SyncContract), GetSecurityTokenServiceBinding(), securityTokenServiceAddress)); securityTokenServiceHost = new WSTrustServiceHost(securityTokenServiceConfiguration, new Uri(securityTokenServiceAddress)); securityTokenServiceHost.Open(); Console.WriteLine("The security token service has started at {0}.\n", securityTokenServiceAddress); // // Invoke the client // echoChannelFactory = new ChannelFactory <IEcho>(GetClientBinding(), new EndpointAddress(new Uri(serviceAddress), EndpointIdentity.CreateDnsIdentity("localhost"))); IEcho client = echoChannelFactory.CreateChannel(); ((IClientChannel)client).OperationTimeout = TimeSpan.MaxValue; Console.WriteLine("The client sent a request to the STS to retrieve a SAML token and then sent the hello request to the echo service.\n"); Console.WriteLine("The echo service finally returned '{0}'.\n", client.Echo("Hello")); Console.WriteLine("Press [Enter] to continue."); Console.ReadLine(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } finally { try { if (echoChannelFactory != null) { echoChannelFactory.Close(); } if (serviceHost != null) { serviceHost.Close(); } if (securityTokenServiceHost != null) { securityTokenServiceHost.Close(); } } catch (CommunicationException) { } } }
void InvokeEchoCallback(IEcho client) { client.Echo("hi"); }
static void Main() { ServiceHost serviceHost = null; ChannelFactory <IEcho> echoChannelFactory = null; WSTrustServiceHost trustServiceHost = null; try { CustomTokenHandler handler = new CustomTokenHandler(); // // Start the service // serviceHost = new ServiceHost(typeof(EchoService)); string serviceAddress = "http://" + Environment.MachineName + ":8080/EchoService"; ServiceMetadataBehavior metadataBehavior = new ServiceMetadataBehavior(); metadataBehavior.HttpGetEnabled = true; metadataBehavior.HttpGetUrl = new Uri(serviceAddress); serviceHost.Description.Behaviors.Add(metadataBehavior); serviceHost.AddServiceEndpoint(typeof(IEcho), GetServiceBinding(), serviceAddress); serviceHost.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexHttpBinding(), serviceAddress + "/mex"); serviceHost.Credentials.ServiceCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.Root, X509FindType.FindByThumbprint, thumbprint); FederatedServiceCredentials.ConfigureServiceHost(serviceHost); // // Update the service credentials so that it can deserialize the custom token // (( FederatedServiceCredentials )serviceHost.Credentials).SecurityTokenHandlers.Add(handler); serviceHost.Open(); Console.WriteLine("The echo service has started at {0}.\n", serviceAddress); // // Start the SecurityTokenService // X509Certificate2 certificate = CertificateUtil.GetCertificate(StoreName.Root, StoreLocation.LocalMachine, thumbprint); SigningCredentials credentials = new X509SigningCredentials(certificate); SecurityTokenServiceConfiguration securityTokenServiceConfiguration = new SecurityTokenServiceConfiguration(securityTokenServiceAddress, credentials); securityTokenServiceConfiguration.SecurityTokenService = typeof(SampleTokenService); // register a handler to the SecurityTokenService here so that it can issue the custom token securityTokenServiceConfiguration.SecurityTokenHandlers.Add(handler); // Add the STS endpoint information securityTokenServiceConfiguration.TrustEndpoints.Add( new ServiceHostEndpointConfiguration(typeof(IWSTrust13SyncContract), GetSecurityTokenServiceBinding(), securityTokenServiceAddress)); securityTokenServiceConfiguration.ServiceCertificate = certificate; trustServiceHost = new WSTrustServiceHost(securityTokenServiceConfiguration, new Uri(securityTokenServiceAddress)); trustServiceHost.Open(); Console.WriteLine("The security token service has started at {0}.\n", securityTokenServiceAddress); // // Invoke the client // echoChannelFactory = new ChannelFactory <IEcho>(GetClientBinding(), new EndpointAddress(new Uri(serviceAddress), EndpointIdentity.CreateDnsIdentity("localhost"))); IEcho client = echoChannelFactory.CreateChannel(); ((IClientChannel)client).OperationTimeout = TimeSpan.MaxValue; string echoedString = client.Echo("Hello"); Console.WriteLine("The echo service returns '{0}'. \n", echoedString); Console.WriteLine("Press [Enter] to close service."); Console.ReadLine(); echoChannelFactory.Close(); Console.WriteLine("Press [Enter] to continue."); Console.ReadLine(); } catch (CommunicationException e) { Console.WriteLine(e.Message); if (echoChannelFactory != null) { echoChannelFactory.Abort(); } } catch (TimeoutException e) { Console.WriteLine(e.Message); if (echoChannelFactory != null) { echoChannelFactory.Abort(); } } catch (Exception e) { Console.Out.WriteLine(e.InnerException.Message); } finally { if (serviceHost != null && serviceHost.State != CommunicationState.Faulted) { serviceHost.Close(); } if (trustServiceHost != null && trustServiceHost.State != CommunicationState.Faulted) { trustServiceHost.Close(); } } }