Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Client client = new Client(); // <- the wcf ClientBase implementation for the serivce.
- client.Endpoint.Behaviors.Remove<ClientCredentials>();
- client.Endpoint.Behaviors.Add<ClientCredentialsEx>();
- client.DisplayInitializationUI();
- client.InnerChannel.Open();
- public class ClientCredentialsEx : ClientCredentials
- {
- public ClientCredentialsEx() : base() { }
- public ClientCredentialsEx(ClientCredentialsEx other) : base(other) { }
- public override void ApplyClientBehavior(ServiceEndpoint serviceEndpoint, ClientRuntime behavior)
- {
- behavior.InteractiveChannelInitializers.Add(new ShowCredentialUI());
- base.ApplyClientBehavior(serviceEndpoint, behavior);
- }
- protected override ClientCredentials CloneCore()
- {
- return new ClientCredentialsEx(this);
- }
- }
- public IAsyncResult BeginDisplayInitializationUI(IClientChannel channel, AsyncCallback callback, object state)
- {
- string host = "";
- CREDUI_INFO info = new CREDUI_INFO();
- string username = string.Empty, password = string.Empty;
- CREDUI_FLAGS flags = CREDUI_FLAGS.GENERIC_CREDENTIALS |
- CREDUI_FLAGS.SHOW_SAVE_CHECK_BOX |
- CREDUI_FLAGS.EXPECT_CONFIRMATION;
- bool savePwd = false;
- // PromptForCredentials calls interop credui to challenge the user for username/password/smartcard.
- CredUIReturnCodes result = PromptForCredentials(ref info, host, 0, ref username,
- ref password, ref savePwd, flags);
- ChannelParameterCollection collection = channel.GetProperty<ChannelParameterCollection>();
- collection.Add(new NetworkCredential(username, password));
- return new AsyncResult();
- }
Add Comment
Please, Sign In to add comment