/// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <object> PostAsync(this IEcho operations, CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.PostWithHttpMessagesAsync(null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
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 DoNothingCallback(IEcho client) { // do nothing }
void InvokeEchoCallback(IEcho client) { client.Echo("hi"); }
/// <param name='operations'> /// The operations group for this extension method. /// </param> public static object Post(this IEcho operations) { return(Task.Factory.StartNew(s => ((IEcho)s).PostAsync(), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult()); }
public static void Main() { //The URL for the server string echoUrl = "tcp://localhost:9998/Echo"; string paldindromeUrl = "tcp://localhost:9998/PalindromeChecker"; //Register the channel try { TcpChannel tcpChannel = new TcpChannel(); ChannelServices.RegisterChannel(tcpChannel, false); //Get the Echo remote object Type echoType = typeof(IEcho); IEcho remoteEcho = (IEcho)Activator.GetObject(echoType, echoUrl); //Get the PaldindromeChecker remote object Type palindromeCheckerType = typeof(IPalindromeChecker); IPalindromeChecker remotePalindromeChecker = (IPalindromeChecker)Activator.GetObject(palindromeCheckerType, paldindromeUrl); string input = ""; Console.WriteLine("\nWrite a word to the server and wait for the server to check if the word is palindrome. \n (Type 'quit' to exit)"); //Boolean flag = false; //while (input != "QUIT") while (!string.Equals(input, "quit", StringComparison.OrdinalIgnoreCase)) { Console.WriteLine("\nEnter word to check whether it is palindrome or 'quit' to exit the program"); input = Console.ReadLine(); if (string.Equals(input, "")) { Console.WriteLine("You didnt enter anything, this cannot be checked to be a palindrome, please write a word"); Console.WriteLine("\nEnter word to check whether it is palindrome"); input = Console.ReadLine(); } Console.WriteLine(remoteEcho.Send(input.Replace(" ", "").Trim())); Boolean palindrome = remotePalindromeChecker.isPalindrome(input.Replace(" ", "").Trim()); Console.WriteLine("It is " + palindrome + " that the message was a palindrome."); } } catch (SocketException ex) { Console.WriteLine("Could not establish connection with server or a existing connection was forcefully disconnected"); Console.WriteLine(ex.GetType().FullName); Console.WriteLine(ex.Message); } catch (ArgumentNullException ex) { Console.WriteLine("The chnl parameter is null."); Console.WriteLine(ex.GetType().FullName); Console.WriteLine(ex.Message); } catch (RemotingException ex) { Console.WriteLine("The channel has already been registered."); Console.WriteLine(ex.GetType().FullName); Console.WriteLine(ex.Message); } catch (MemberAccessException ex) { Console.WriteLine("This member was invoked with a late-binding mechanism."); Console.WriteLine(ex.GetType().FullName); Console.WriteLine(ex.Message); } catch (SecurityException ex) { Console.WriteLine("At least one of the callers higher in the callstack does not have permission to configure remoting types and channels."); Console.WriteLine(ex.GetType().FullName); Console.WriteLine(ex.Message); } }
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(); } } }