private void CallWcfServiceButton_Click(object sender, RoutedEventArgs e) { var token = ""; if (_response != null && _response.Values.ContainsKey("access_token")) { //client.SetBearerToken(_response.AccessToken); token = _response.AccessToken; } CustomBinding customTokenBinding = CreateCustomTokenBinding(); customTokenBinding.ReceiveTimeout = new TimeSpan(12, 0, 0); customTokenBinding.SendTimeout = new TimeSpan(12, 0, 0); customTokenBinding.OpenTimeout = new TimeSpan(12, 0, 0); customTokenBinding.CloseTimeout = new TimeSpan(12, 0, 0); var endPointIdentity = new DnsEndpointIdentity("idsrv3test"); var serviceAddress = new EndpointAddress(new Uri("http://localhost:2729/Service1.svc"), endPointIdentity); // Create a client with given client endpoint configuration var channelFactory = new ChannelFactory <IService1>(customTokenBinding, serviceAddress); // configure the credit card credentials on the channel factory CustomTokenClientCredentials credentials = new CustomTokenClientCredentials(token); // configure the service certificate on the credentials credentials.ServiceCertificate.DefaultCertificate = LoadCertificate(); // replace ClientCredentials with CreditCardClientCredentials channelFactory.Endpoint.Behaviors.Remove(typeof(ClientCredentials)); channelFactory.Endpoint.Behaviors.Add(credentials); var client = channelFactory.CreateChannel(); var response = client.GetIdentityData(); ((ICommunicationObject)client).Close(); channelFactory.Close(); Textbox1.Text = response; }
static void CallServiceCustomToken(string token) { Binding customTokenBinding = CreateCustomTokenBinding(); customTokenBinding.ReceiveTimeout = new TimeSpan(12, 0, 0); customTokenBinding.SendTimeout = new TimeSpan(12, 0, 0); customTokenBinding.OpenTimeout = new TimeSpan(12, 0, 0); customTokenBinding.CloseTimeout = new TimeSpan(12, 0, 0); var endPointIdentity = new DnsEndpointIdentity("idsrv3test"); var serviceAddress = new EndpointAddress(new Uri("http://localhost:2729/Service1.svc"), endPointIdentity); // Create a client with given client endpoint configuration var channelFactory = new ChannelFactory <IService1>(customTokenBinding, serviceAddress); // configure the credit card credentials on the channel factory CustomTokenClientCredentials credentials = new CustomTokenClientCredentials(token); // configure the service certificate on the credentials credentials.ServiceCertificate.DefaultCertificate = LoadCertificate(); // replace ClientCredentials with CreditCardClientCredentials channelFactory.Endpoint.Behaviors.Remove(typeof(ClientCredentials)); channelFactory.Endpoint.Behaviors.Add(credentials); var client = channelFactory.CreateChannel(); var response = client.GetIdentityData(); ((IChannel)client).Close(); channelFactory.Close(); "\n\nService claims:\n".ConsoleGreen(); Console.WriteLine(response); Console.ReadLine(); }