简体   繁体   English

从客户端传递到WCF的凭据不在此处

[英]Credentials passed from client to WCF do not make it there

Im trying to pass windows credentials into WCF service that requires windows authentication but it seems like my credentials are not making it into the service. 我试图将Windows凭据传递到需要Windows身份验证的WCF服务中,但似乎我的凭据没有将其纳入服务中。 My service does not throw any errors but when I check either of the 2 below they are empty. 我的服务没有引发任何错误,但是当我检查以下两个2之一时,它们为空。 var user = WindowsIdentity.GetCurrent().User; var callerUserName = ServiceSecurityContext.Current.WindowsIdentity.User;

Here is my client side code ServiceReference1.DispatchServiceClient service = new DispatchServiceClient(); service.ClientCredentials.Windows.ClientCredential = ServiceCredentialsManager.GetNetworkCredentials(); service.ClientCredentials.UserName.UserName= ServiceCredentialsManager.GetNetworkCredentials().UserName; service.ClientCredentials.UserName.Password = ServiceCredentialsManager.GetNetworkCredentials().Password; 这是我的客户端代码 ServiceReference1.DispatchServiceClient service = new DispatchServiceClient(); service.ClientCredentials.Windows.ClientCredential = ServiceCredentialsManager.GetNetworkCredentials(); service.ClientCredentials.UserName.UserName= ServiceCredentialsManager.GetNetworkCredentials().UserName; service.ClientCredentials.UserName.Password = ServiceCredentialsManager.GetNetworkCredentials().Password; ServiceReference1.DispatchServiceClient service = new DispatchServiceClient(); service.ClientCredentials.Windows.ClientCredential = ServiceCredentialsManager.GetNetworkCredentials(); service.ClientCredentials.UserName.UserName= ServiceCredentialsManager.GetNetworkCredentials().UserName; service.ClientCredentials.UserName.Password = ServiceCredentialsManager.GetNetworkCredentials().Password;

Client config - 客户端配置-

 <basicHttpBinding>
    <binding name="BasicHttpsBinding_IDispatchService">
      <security mode="Transport">
        <transport clientCredentialType="Windows" />
      </security>
    </binding>
  </basicHttpBinding>
  <basicHttpsBinding>
    <binding name="basicHttpsBindingMax" maxBufferSize="999999999"
      maxReceivedMessageSize="999999999">
      <security mode="Transport">
        <transport clientCredentialType="Windows" />
      </security>
    </binding>
  </basicHttpsBinding>
</bindings>

Service config - 服务配置-

 <system.serviceModel>
      <bindings>
      <basicHttpBinding>
          <binding name="basicHttpsBinding">
              <security mode="Transport">
                  <transport clientCredentialType="Windows" />
              </security>
          </binding>
      </basicHttpBinding>
  </bindings>
<behaviors>
  <serviceBehaviors>
    <behavior>
      <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
      <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<protocolMapping>
  <add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />

Please note that in order to use Windows Authentication both service and the client application has to be run in the same Windows domain. 请注意,为了使用Windows身份验证,服务和客户端应用程序必须在同一Windows域中运行。

Please also make sure that that in the client the values You assign are not empty. 还请确保您在客户端中分配的值不为空。 Usually, the password isn't accessible from code when Windows authentication is used. 通常,使用Windows身份验证时无法从代码访问密码。

If the service client is authenticated using Windows Authentication, You probably shouldn't manually pass the credentials to the service. 如果使用Windows身份验证对服务客户端进行了身份验证,则您可能不应该手动将凭据传递给服务。 The authentication process should be handled automatically by the WCF and doesn't rely simply on sending the credentials, but for example it can use Kerberos ticket instead. 身份验证过程应由WCF自动处理,而不是仅依赖于发送凭据,而是例如可以使用Kerberos票证。

Please take a look here for some description and code samples for client and service: 请在此处查看有关客户端和服务的一些描述和代码示例:

Update 更新

After some research I've found several sources suggesting that setting credentials appropriately in the client code may enable WCF to authenticate from outside the domain: 经过一些研究,我发现有几个来源表明,在客户端代码中适当设置凭据可能使WCF能够从域外部进行身份验证:

The code samples suggested in those articles are similar, but slightly different to the one You've posted in the question. 这些文章中建议的代码示例与您在问题中发布的代码示例相似,但略有不同。 I haven't tested those methods and they may not work in all scenarios. 我尚未测试这些方法,它们可能无法在所有情况下都有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM