Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm not sure that I understand your question, but if you need the domain name of the Windows user making the call to a service operation, use this:</p> <pre><code>OperationContext.Current.ServiceSecurityContext.PrimaryIdentity.Name </code></pre> <p>This will return "{domain}\{username}". </p> <p>Try this and let me know what you think (you'll probably want to paste this code into an mstest project):</p> <pre><code>[TestClass] public class AlternativeCredentials { // Contracts [ServiceContract] interface IMyContract { [OperationContract] string GetUserName(); } // Service [ServiceBehavior(IncludeExceptionDetailInFaults = true)] class MyService : IMyContract { public string GetUserName() { return OperationContext.Current.ServiceSecurityContext.PrimaryIdentity.Name; } } // Client class MyContractClient : ClientBase&lt;IMyContract&gt;, IMyContract { public MyContractClient() { } public MyContractClient(Binding binding, string address) : base(binding, new EndpointAddress(address)) { } public string GetUserName() { return Channel.GetUserName(); } } #region Host static string address = "net.tcp://localhost:8001/" + Guid.NewGuid().ToString(); static ServiceHost host; [ClassInitialize()] public static void MyClassInitialize(TestContext testContext) { host = new ServiceHost(typeof(MyService)); host.AddServiceEndpoint(typeof(IMyContract), new NetTcpBinding(), address); host.Open(); } [ClassCleanup()] public static void MyClassCleanup() { if (host.State == CommunicationState.Opened) host.Close(); } #endregion [TestMethod] public void UseUserNameCredentials() { using (MyContractClient proxy = new MyContractClient(new NetTcpBinding(), address)) { proxy.ClientCredentials.UserName.UserName = "MyUsername"; proxy.ClientCredentials.UserName.Password = "MyPassword"; proxy.Open(); Assert.AreEqual("EMS\\magood", proxy.GetUserName()); proxy.Close(); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload