示例#1
0
        static void Main(string[] args)
        {
            // allow server certificate that doesn't match the host in the endpoint address
            ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(IgnoreSubjectNameMismatch);

            string uri = "https://" + Environment.MachineName + ":8443/TestService/BinaryEncoderOverHTTPS";

            if (args.Length > 0)
            {
                uri = args[0];
            }
            EndpointAddress address = new EndpointAddress(uri);
            NetHttpBinding  binding = new NetHttpBinding();
            ChannelFactory <IEchoService> factory = new ChannelFactory <IEchoService>(binding, address);

            factory.Open();
            IEchoService service = factory.CreateChannel();

            Console.WriteLine(service.Echo("'Test string passed for calling service using code'"));

            Console.WriteLine("called service successfully using binding in code");

            factory = new ChannelFactory <IEchoService>("EchoServer");
            factory.Open();
            service = factory.CreateChannel();

            Console.WriteLine(service.Echo("'Test string passed for calling service using code'"));
            Console.WriteLine("called service successfully using binding from config. Press enter to exit...");

            Console.ReadLine();
        }
示例#2
0
        static void Main(string[] args)
        {
            Console.WriteLine(
                "Press <enter> to open a channel and send a request.");

            Console.ReadLine();

            MessageHeader shareableInstanceContextHeader = MessageHeader.CreateHeader(
                CustomHeader.HeaderName,
                CustomHeader.HeaderNamespace,
                Guid.NewGuid().ToString());

            ChannelFactory <IEchoService> channelFactory =
                new ChannelFactory <IEchoService>("echoservice");

            IEchoService proxy = channelFactory.CreateChannel();


            using (new OperationContextScope((IClientChannel)proxy))
            {
                OperationContext.Current.OutgoingMessageHeaders.Add(shareableInstanceContextHeader);
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("Service returned: " + proxy.Echo("Apple"));
                Console.ForegroundColor = ConsoleColor.Gray;
            }

            ((IChannel)proxy).Close();

            Console.WriteLine("Channel No 1 closed.");

            Console.WriteLine(
                "Press <ENTER> to send another request from a different channel " +
                "to the same instance. ");

            Console.ReadLine();

            proxy = channelFactory.CreateChannel();

            using (new OperationContextScope((IClientChannel)proxy))
            {
                OperationContext.Current.OutgoingMessageHeaders.Add(shareableInstanceContextHeader);
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("Service returned: " + proxy.Echo("Apple"));
                Console.ForegroundColor = ConsoleColor.Gray;
            }

            ((IChannel)proxy).Close();

            Console.WriteLine("Channel No 2 closed.");

            Console.WriteLine("Press <ENTER> to complete test.");
            Console.ReadLine();
        }
示例#3
0
        public void Soap11Wss10(X509Certificate2 cert)
        {
            var binding = new CustomBinding();

            binding.Elements.Add(new CustomSecurityBindingElement()
            {
                MessageSecurityVersion = SecurityVersion.WSSecurity10
            });
            binding.Elements.Add(new TextMessageEncodingBindingElement()
            {
                MessageVersion = MessageVersion.Soap11
            });
            binding.Elements.Add(new HttpsTransportBindingElement()
            {
                //BypassProxyOnLocal = false,
                //UseDefaultWebProxy = false,
                //ProxyAddress = new Uri("http://localhost:8866")
            });

            var ep = new EndpointAddress("https://localhost:8080/services/echo/soap11wss10");
            ChannelFactory <IEchoService> channelFactory = new ChannelFactory <IEchoService>(binding, ep);

            channelFactory.Credentials.ClientCertificate.Certificate = cert;

            IEchoService client = channelFactory.CreateChannel();

            String pong = client.Echo("boe");

            Assert.Equal("boe", pong);
        }
        public void JAVAServiceSSLConversation()
        {
            ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); };

            SecurityToken bootstrapSecurityToken = BootstrapSecurityTokenGenerator.MakeBootstrapSecurityToken();

            Uri audience = new Uri("https://oiosaml.trifork.com:8082/poc-provider/GenevaProviderService");

            RequestSecurityToken rst = WSTrustClientFactory.MakeOnBehalfOfSTSRequestSecurityToken(bootstrapSecurityToken, clientCertifikat, audience, requestClaims);

            var token = STSConnection.GetIssuedToken(rst);

            IEchoService echoService = WebserviceproviderChannelFactory.CreateChannelWithIssuedToken <IEchoService>(token, clientCertifikat, serviceCertifikat, new EndpointAddress(new Uri("https://oiosaml.trifork.com:8082/poc-provider/GenevaProviderService")));

            var req = new echo();

            req.structureToEcho       = new Structure();
            req.structureToEcho.value = "kvlsjvsldk";
            req.Framework             = new LibertyFrameworkHeader();

            var reply = echoService.Echo(req);

            Assert.IsNotNull(reply.Framework);
            Assert.IsNotNull(reply.structureToEcho.value);
        }
示例#5
0
        static void Main(string[] args)
        {
            //service uses Discovery...
            var services = FindServices();
            var address  = services.Endpoints[0].Address;
            var binding  = new BasicHttpBinding();

            Console.WriteLine("Found service at: {0}", address);

            //create ChannelFactory Client to found echoservice
            ChannelFactory <IEchoService> factory =
                new ChannelFactory <IEchoService>(binding, address);

            IEchoService instance = factory.CreateChannel();

            string message = null;

            do
            {
                Console.Write("Enter a message, or blank to exit: ");
                message = Console.ReadLine();
                Console.WriteLine(instance.Echo(message));
            } while (!string.IsNullOrEmpty(message));

            factory.Close();
        }
示例#6
0
        public void soap12Plain()
        {
            var binding = new WSHttpBinding(SecurityMode.Transport);
            var ep      = new EndpointAddress("https://localhost:8080/services/echo/soap12");
            ChannelFactory <IEchoService> channelFactory = new ChannelFactory <IEchoService>(binding, ep);

            IEchoService client = channelFactory.CreateChannel();

            String pong = client.Echo("boe");

            Assert.Equal("boe", pong);
        }
示例#7
0
        public void soap11Plain()
        {
            var binding = new BasicHttpsBinding();
            var ep      = new EndpointAddress("https://localhost:8080/services/echo/soap11");
            ChannelFactory <IEchoService> channelFactory = new ChannelFactory <IEchoService>(binding, ep);

            IEchoService client = channelFactory.CreateChannel();

            String pong = client.Echo("boe");

            Assert.Equal("boe", pong);
        }
示例#8
0
        static void Main(string[] args)
        {
            using (var factory = new ChannelFactory <IEchoService>("EchoService"))
            {
                IEchoService channel = null;

                try
                {
                    channel = factory.CreateChannel();
                    Console.WriteLine(channel.Echo("test"));
                    Console.WriteLine(channel.Echo(null));
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    Console.WriteLine($"Channel state: {((IClientChannel)channel).State}");
                }

                Console.WriteLine(channel.Echo("Still Active"));
                Console.ReadKey();
            }
        }
示例#9
0
        /// <summary>
        /// Called by the framework when the user clicks the "apply" menu item or toolbar button.
        /// </summary>
        public void Apply()
        {
            try
            {
                _echoService = (IEchoService)Activator.GetObject(typeof(IEchoService), RemotingSettings.Default.RemoteHostUrl);

                this.Context.DesktopWindow.ShowMessageBox(_echoService.Echo("If you see this, remoting is working."),
                                                          MessageBoxActions.Ok);
            }
            catch (Exception e)
            {
                ExceptionHandler.Report(e, this.Context.DesktopWindow);
            }
        }
示例#10
0
                static void Main(string[]  args)
                 {
                        Binding binding           =  new BasicHttpBinding();
                        EndpointAddress endpoint  =  new EndpointAddress(new Uri("http://localhost:5000/EchoService.svc"));
                        ChannelFactory <IEchoService>  channelFactory  =  new ChannelFactory <IEchoService>(binding,  endpoint);

                        IEchoService echoService  =  channelFactory.CreateChannel();

                        string echo  =  echoService.Echo("Bonjour DSED !");
                        try
                         {
                                echoService.CalculInteretAnnuel(-1,  0);
                            
            }
                        catch (Exception ex)
                         {
                                Console.Error.WriteLine(ex.Message);
                            
            }

                        int nombreEssais         =  0;
                        int nombreMaximumEssais  =  3;
                        bool appelEffectue       =  false;
                        decimal interet          =   - 1m;
                        while (!appelEffectue  &&  nombreEssais  <  nombreMaximumEssais)
                         {
                                ++ nombreEssais;
                                try
                                 {
                                        interet        =  echoService.CalculInteretAnnuel(100,   .199m);
                                        appelEffectue  =  true;
                                    
                }
                                catch (Exception)
                                 {
                                        if (nombreEssais  >=  nombreMaximumEssais)
                                         {
                                                throw;
                                            
                    }
                                    
                }
                            
            }
                    
        }
        static void Main(string[] args)
        {
            //In real implementation, use server IP instead of localhost
            ChannelFactory <IEchoService> factory = new ChannelFactory <IEchoService>(new BasicHttpBinding(), new EndpointAddress("http://localhost:8000/Echo"));
            IEchoService proxy            = factory.CreateChannel();
            int          processedSeccond = 0;

            while (true)
            {
                var dateTime = DateTime.Now;
                if (dateTime.Second % 10 == 0 && dateTime.Second != processedSeccond)
                {
                    processedSeccond = dateTime.Second;
                    string data = dateTime.ToString();    //or Console readLine for manual data entry
                    Console.WriteLine("Recieved Response: " + proxy.Echo(str));
                }
            }
        }
示例#12
0
        public void soap12Wss10Rsa()
        {
            var binding = new WSHttpBinding(SecurityMode.TransportWithMessageCredential);

            binding.Security.Message.ClientCredentialType       = MessageCredentialType.Certificate;
            binding.Security.Message.NegotiateServiceCredential = false;
            binding.Security.Message.EstablishSecurityContext   = false;

            var ep = new EndpointAddress("https://localhost:8080/services/echo/soap12wss10");
            ChannelFactory <IEchoService> channelFactory = new ChannelFactory <IEchoService>(binding, ep);

            channelFactory.Credentials.ClientCertificate.Certificate = rsa;

            IEchoService client = channelFactory.CreateChannel();

            String pong = client.Echo("boe");

            Assert.Equal("boe", pong);
        }
        public void MissingLibertyHeader()
        {
            SecurityToken bootstrapSecurityToken = BootstrapSecurityTokenGenerator.MakeBootstrapSecurityToken();

            Uri audience = new Uri("http://localhost/Echo/service.svc/Echo");

            RequestSecurityToken rst = WSTrustClientFactory.MakeOnBehalfOfSTSRequestSecurityToken(bootstrapSecurityToken, clientCertifikat, audience, requestClaims);

            var token = STSConnection.GetIssuedToken(rst);

            IEchoService echoService = WebserviceproviderChannelFactory.CreateChannelWithIssuedToken <IEchoService>(token, clientCertifikat, serviceCertifikat, new EndpointAddress(new Uri("http://lh-z3jyrnwtj9d7/EchoWebserviceProvider/service.svc/Echo"), new DnsEndpointIdentity(DnsIdentityForServiceCertificates)));

            var req = new echo();

            req.structureToEcho = new Structure();
            req.Framework       = null; //Failure

            echoService.Echo(req);
        }
示例#14
0
        static void MainEx(string[] args)
        {
            try
            {
                EndpointAddress ep = new EndpointAddress("http://localhost:8088/HelloIndigo/EchoService");

                IEchoService proxy
                    = ChannelFactory <IEchoService> .CreateChannel(new BasicHttpBinding(),
                                                                   ep);

                string s = null;
                proxy.Echo(out s, "Echo, me!");

                Console.WriteLine(string.Format("HelloIndigo.HelloIndigoService::Echo : {0}", s));
            }
            catch (Exception exp)
            {
                Trace.WriteLine(exp.ToString());
            }
        }
示例#15
0
        public void federation()
        {
            //var stsEp = new EndpointAddress("https://services-int.ehealth.fgov.be/IAM/SingleSignOnService/v1");
            var stsEp = new EndpointAddress("https://localhost:8080/services/echo/soap12wss10");

            var stsBinding = new WSHttpBinding(SecurityMode.TransportWithMessageCredential);

            stsBinding.Security.Message.ClientCredentialType       = MessageCredentialType.Certificate;
            stsBinding.Security.Message.NegotiateServiceCredential = false;
            stsBinding.Security.Message.EstablishSecurityContext   = false;

            WSFederationHttpBinding binding;

#if NETFRAMEWORK
            binding = new WSFederationHttpBinding();
            binding.Security.Mode = WSFederationHttpSecurityMode.TransportWithMessageCredential;
            binding.Security.Message.IssuedKeyType   = SecurityKeyType.AsymmetricKey;
            binding.Security.Message.IssuerAddress   = stsEp;
            binding.Security.Message.IssuerBinding   = stsBinding;
            binding.Security.Message.IssuedTokenType = "http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV1.1";

            ClaimTypeRequirement ctr = new ClaimTypeRequirement("http://example.org/claim/c1", false);
            binding.Security.Message.ClaimTypeRequirements.Add(ctr);
#else
            var parameters = WSTrustTokenParameters.CreateWSFederationTokenParameters(stsBinding, stsEp);
            parameters.KeyType   = SecurityKeyType.AsymmetricKey;
            parameters.TokenType = "http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV1.1";
            binding = new WSFederationHttpBinding(parameters);
#endif
            var ep = new EndpointAddress("https://localhost:8080/services/echo/soap12");
            ChannelFactory <IEchoService> channelFactory = new ChannelFactory <IEchoService>(binding, ep);
            channelFactory.Credentials.ClientCertificate.Certificate = rsa;

            IEchoService client = channelFactory.CreateChannel();

            String pong = client.Echo("boe");
            Assert.Equal("boe", pong);
        }
        public void DotNetServiceSSLConversation()
        {
            ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); };

            SecurityToken bootstrapSecurityToken = BootstrapSecurityTokenGenerator.MakeBootstrapSecurityToken();

            Uri audience = new Uri("http://localhost/Echo/service.svc/Echo");

            RequestSecurityToken rst = WSTrustClientFactory.MakeOnBehalfOfSTSRequestSecurityToken(bootstrapSecurityToken, clientCertifikat, audience, requestClaims);

            var token = STSConnection.GetIssuedToken(rst);

            IEchoService echoService = WebserviceproviderChannelFactory.CreateChannelWithIssuedToken <IEchoService>(token, clientCertifikat, serviceCertifikat, new EndpointAddress(new Uri("https://lh-z3jyrnwtj9d7/EchoWebserviceProvider/service.svc/Echo")));

            var req = new echo();

            req.structureToEcho = new Structure();
            req.Framework       = new LibertyFrameworkHeader();

            var reply = echoService.Echo(req);

            Assert.IsNotNull(reply.Framework);
        }
示例#17
0
 public string Echo(string s = "<null>")
 {
     return(_echoService.Echo(s));
 }
示例#18
0
        static void Main()
        {
            // Create the custom binding and an endpoint address for the service.
            Binding         multipleTokensBinding        = BindingHelper.CreateMultiFactorAuthenticationBinding();
            EndpointAddress serviceAddress               = new EndpointAddress("http://localhost/servicemodelsamples/service.svc");
            ChannelFactory <IEchoService> channelFactory = null;
            IEchoService client = null;

            Console.WriteLine("Username authentication required.");
            Console.WriteLine("Provide a valid machine or domain account. [domain\\user]");
            Console.WriteLine("   Enter username:"******"   Enter password:"******"";
            ConsoleKeyInfo info     = Console.ReadKey(true);

            while (info.Key != ConsoleKey.Enter)
            {
                if (info.Key != ConsoleKey.Backspace)
                {
                    if (info.KeyChar != '\0')
                    {
                        password += info.KeyChar;
                    }
                    info = Console.ReadKey(true);
                }
                else if (info.Key == ConsoleKey.Backspace)
                {
                    if (password != "")
                    {
                        password = password.Substring(0, password.Length - 1);
                    }
                    info = Console.ReadKey(true);
                }
            }

            for (int i = 0; i < password.Length; i++)
            {
                Console.Write("*");
            }

            Console.WriteLine();

            try
            {
                // Create a proxy with the previously create binding and endpoint address
                channelFactory = new ChannelFactory <IEchoService>(multipleTokensBinding, serviceAddress);

                // configure the username credentials, the client certificate and the server certificate on the channel factory
                channelFactory.Credentials.UserName.UserName = username;
                channelFactory.Credentials.UserName.Password = password;

                channelFactory.Credentials.ClientCertificate.SetCertificate("CN=client.com", StoreLocation.CurrentUser, StoreName.My);
                channelFactory.Credentials.ServiceCertificate.SetDefaultCertificate("CN=localhost", StoreLocation.LocalMachine, StoreName.My);

                client = channelFactory.CreateChannel();

                Console.WriteLine("Echo service returned: {0}", client.Echo());

                ((IChannel)client).Close();
                channelFactory.Close();
            }
            catch (CommunicationException e)
            {
                Abort((IChannel)client, channelFactory);

                // if there is a fault then print it out
                FaultException fe  = null;
                Exception      tmp = e;
                while (tmp != null)
                {
                    fe = tmp as FaultException;
                    if (fe != null)
                    {
                        break;
                    }
                    tmp = tmp.InnerException;
                }
                if (fe != null)
                {
                    Console.WriteLine("The server sent back a fault: {0}", fe.CreateMessageFault().Reason.GetMatchingTranslation().Text);
                }
                else
                {
                    Console.WriteLine("The request failed with exception: {0}", e);
                }
            }
            catch (TimeoutException)
            {
                Abort((IChannel)client, channelFactory);
                Console.WriteLine("The request timed out");
            }
            catch (Exception e)
            {
                Abort((IChannel)client, channelFactory);
                Console.WriteLine("The request failed with unexpected exception: {0}", e);
            }

            Console.WriteLine();
            Console.WriteLine("Press <ENTER> to terminate client.");
            Console.ReadLine();
        }
示例#19
0
        static void Main()
        {
            string   creditCardNumber = "11111111";
            DateTime expirationTime   = new DateTime(2010, 12, 15, 0, 0, 0, 0, DateTimeKind.Utc);
            string   issuer           = Constants.TestCreditCardIssuer;
            ChannelFactory <IEchoService> channelFactory = null;
            IEchoService client = null;


            Console.WriteLine("Please enter your credit card information:");
            Console.WriteLine("Please enter a credit card number (hit [enter] to pick 11111111 - a valid number on file): ");
            string input = Console.ReadLine();

            if (input.Trim() != string.Empty)
            {
                creditCardNumber = input;
                bool readDate = false;
                while (!readDate)
                {
                    Console.WriteLine("Please enter the expiration time (yyyy/mm/dd): ");
                    input = Console.ReadLine().Trim();
                    try
                    {
                        expirationTime = DateTime.Parse(input, System.Globalization.DateTimeFormatInfo.InvariantInfo, System.Globalization.DateTimeStyles.AdjustToUniversal);
                        readDate       = true;
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("You did not enter a valid date format. Please try again");
                    }
                }
                Console.WriteLine("Please enter the issuer of the credit card (hit enter to pick {0}", Constants.TestCreditCardIssuer);
                input = Console.ReadLine().Trim();
                if (input != string.Empty)
                {
                    issuer = input;
                }
            }
            try
            {
                Binding         creditCardBinding = BindingHelper.CreateCreditCardBinding();
                EndpointAddress serviceAddress    = new EndpointAddress("http://localhost/servicemodelsamples/service.svc");

                // Create a client with given client endpoint configuration
                channelFactory = new ChannelFactory <IEchoService>(creditCardBinding, serviceAddress);

                // configure the credit card credentials on the channel factory
                CreditCardClientCredentials credentials = new CreditCardClientCredentials(new CreditCardInfo(creditCardNumber, issuer, expirationTime));

                // configure the service certificate on the credentials
                credentials.ServiceCertificate.SetDefaultCertificate("CN=localhost", StoreLocation.LocalMachine, StoreName.My);

                // replace ClientCredentials with CreditCardClientCredentials
                channelFactory.Endpoint.Behaviors.Remove(typeof(ClientCredentials));
                channelFactory.Endpoint.Behaviors.Add(credentials);

                client = channelFactory.CreateChannel();

                Console.WriteLine("Echo service returned: {0}", client.Echo());

                ((IChannel)client).Close();
                channelFactory.Close();
            }
            catch (CommunicationException e)
            {
                Abort((IChannel)client, channelFactory);

                // if there is a fault then print it out
                FaultException fe  = null;
                Exception      tmp = e;
                while (tmp != null)
                {
                    fe = tmp as FaultException;
                    if (fe != null)
                    {
                        break;
                    }
                    tmp = tmp.InnerException;
                }
                if (fe != null)
                {
                    Console.WriteLine("The server sent back a fault: {0}", fe.CreateMessageFault().Reason.GetMatchingTranslation().Text);
                }
                else
                {
                    Console.WriteLine("The request failed with exception: {0}", e);
                }
            }
            catch (TimeoutException)
            {
                Abort((IChannel)client, channelFactory);
                Console.WriteLine("The request timed out");
            }
            catch (Exception e)
            {
                Abort((IChannel)client, channelFactory);
                Console.WriteLine("The request failed with unexpected exception: {0}", e);
            }

            Console.WriteLine();
            Console.WriteLine("Press <ENTER> to terminate client.");
            Console.ReadLine();
        }
示例#20
0
 public string EchoString(string value)
 {
     return(_service.Echo(value));
 }
示例#21
0
文件: Worker.cs 项目: ttak0422/DFrame
 public override async Task ExecuteAsync(WorkerContext context)
 {
     await _client.Echo(context.WorkerId);
 }
示例#22
0
        public async Task <IActionResult> Echo(EchoViewModel model)
        {
            model.Result = await _echoService.Echo(model.Message);

            return(View(model));
        }
示例#23
0
 public IActionResult Get(string value)
 {
     return(Ok(_service.Echo(value)));
 }