Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/301.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WCF。在服务端使用windows凭据_C#_.net_Wcf - Fatal编程技术网

C# WCF。在服务端使用windows凭据

C# WCF。在服务端使用windows凭据,c#,.net,wcf,C#,.net,Wcf,我有WPF和服务的客户。它在安全模式下工作=无。但现在,我需要在服务端提供调用服务在Azure上执行某些操作的用户的Windows凭据。因此,我更改了配置,现在是以下内容: 服务 <system.serviceModel> <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> <client /> <bindings> <wsHttpBindi

我有WPF和服务的客户。它在安全模式下工作=无。但现在,我需要在服务端提供调用服务在Azure上执行某些操作的用户的Windows凭据。因此,我更改了配置,现在是以下内容:

服务

<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<client />
<bindings>
  <wsHttpBinding>
    <binding name="TrackingHoursServiceBinding" maxReceivedMessageSize="620000">
     <!-- WAS THIS 
    <security mode="None">
        <transport clientCredentialType="None" />
        <message establishSecurityContext="false" />
      </security> -->

    <!-- This is my changes  -->
      <security mode="Message">
        <message clientCredentialType="Windows" />
      </security>
    <!-- This my changes  -->
    </binding>
  </wsHttpBinding>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_IPortableService" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" receiveTimeout="00:10:00" sendTimeout="00:10:00" />
  </basicHttpBinding>
</bindings>
<services>
  <service behaviorConfiguration="AAA.AAA.AAA.AAA.TrackingHoursServiceBehavior" name="AAA.AAA.AAA.AAA.TrackingHoursService">
    <endpoint address="" binding="wsHttpBinding" bindingConfiguration="TrackingHoursServiceBinding" contract="AAA.AAA.AAA.AAA.ITrackingHoursService">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    <endpoint address="pcl" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IPortableService" contract="AAA.AAA.AAA.AAA.ITrackingHoursService" />
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="AAA.AAA.AAA.AAA.TrackingHoursServiceBehavior">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<extensions>
  <behaviorExtensions>
    <add name="connectionStatusBehavior" type="Microsoft.ServiceBus.Configuration.ConnectionStatusElement, Microsoft.ServiceBus, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    <add name="transportClientEndpointBehavior" type="Microsoft.ServiceBus.Configuration.TransportClientEndpointBehaviorElement, Microsoft.ServiceBus, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    <add name="serviceRegistrySettings" type="Microsoft.ServiceBus.Configuration.ServiceRegistrySettingsElement, Microsoft.ServiceBus, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
  </behaviorExtensions>
  <bindingElementExtensions>
    <add name="netMessagingTransport" type="Microsoft.ServiceBus.Messaging.Configuration.NetMessagingTransportExtensionElement, Microsoft.ServiceBus,  Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    <add name="tcpRelayTransport" type="Microsoft.ServiceBus.Configuration.TcpRelayTransportElement, Microsoft.ServiceBus, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    <add name="httpRelayTransport" type="Microsoft.ServiceBus.Configuration.HttpRelayTransportElement, Microsoft.ServiceBus, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    <add name="httpsRelayTransport" type="Microsoft.ServiceBus.Configuration.HttpsRelayTransportElement, Microsoft.ServiceBus, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    <add name="onewayRelayTransport" type="Microsoft.ServiceBus.Configuration.RelayedOnewayTransportElement, Microsoft.ServiceBus, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
  </bindingElementExtensions>
  <bindingExtensions>
    <add name="basicHttpRelayBinding" type="Microsoft.ServiceBus.Configuration.BasicHttpRelayBindingCollectionElement, Microsoft.ServiceBus, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    <add name="webHttpRelayBinding" type="Microsoft.ServiceBus.Configuration.WebHttpRelayBindingCollectionElement, Microsoft.ServiceBus, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    <add name="ws2007HttpRelayBinding" type="Microsoft.ServiceBus.Configuration.WS2007HttpRelayBindingCollectionElement, Microsoft.ServiceBus, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    <add name="netTcpRelayBinding" type="Microsoft.ServiceBus.Configuration.NetTcpRelayBindingCollectionElement, Microsoft.ServiceBus, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    <add name="netOnewayRelayBinding" type="Microsoft.ServiceBus.Configuration.NetOnewayRelayBindingCollectionElement, Microsoft.ServiceBus, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    <add name="netEventRelayBinding" type="Microsoft.ServiceBus.Configuration.NetEventRelayBindingCollectionElement, Microsoft.ServiceBus, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    <add name="netMessagingBinding" type="Microsoft.ServiceBus.Messaging.Configuration.NetMessagingBindingCollectionElement, Microsoft.ServiceBus, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
  </bindingExtensions>
</extensions>
</system.serviceModel>


但它们返回空对象。。。。如何解决此问题?

测试后,我发现System.Net.CredentialCache.DefaultCredentials无论在客户端还是服务器上都不会返回null。是否要通过System.Net.CredentialCache.DefaultCredentials获取用户名、密码或域?如果是这种情况,它将返回null,因为ICredentials返回的实例DefaultCredentials不能用于查看当前安全上下文的用户名、密码或域


要使用windows身份验证,您需要在调用时添加windows凭据:calculatorClient.ClientCredentials.windows.ClientCredential.UserName=“Administrator”;calculatorClient.ClientCredentials.Windows.ClientCredential.Password=“Password”@丁鹏,但我认为它应该自动发送调用此服务的用户的凭据客户端在调用服务器时需要提供的是服务器的windows凭据。@丁鹏,但我不想手动执行此操作。我尝试发送使用客户端的用户的凭据。@丁鹏我尝试tcs.ClientCredentials.Windows.ClientCredential=new NetworkCredential(“用户”、“密码”);但是在服务System.Net.CredentialCache.DefaultNetworkCredentials和System.Net.CredentialCache.DefaultCredentials中,它仍然为空。不,我不需要用户名和密码。在服务端,我希望创建WorkItemTrackingHttpClient(Uri baseUrl、VssCredentials凭据)。我可以使用windows凭据创建VssCredentials。因此,我不会将用户凭据传递给VssCredentials构造函数。但当我在服务yes中使用System.Net.CredentialCache.DefaultCredentials时,它似乎不是空的,但似乎也不包含调用服务的用户凭据。可能需要一些默认的证书。idk。我将wsHttpBinding更改为basicHttBinding安全模式=TransportCredentialOnly,transport=NTLM。在IIS设置中启用了匿名和windows身份验证。它的工作部分来自OperationContext.Current.ServiceSecurityContext.WindowsIdentity.Name我看到了任何用户,但System.Net.CredentialCache.DefaultCredentials返回域\计算机名$的凭据。如果我在iis中禁用匿名身份验证,它将完全不起作用DefaultCredentials表示正在运行的应用程序的当前安全上下文的系统凭据。对于客户端应用程序,这些通常是运行应用程序的用户的Windows凭据。对于ASP.NET应用程序,默认凭据是登录用户或模拟用户的用户凭据。
 <system.serviceModel>
<bindings>
  <wsHttpBinding>
    <binding name="TrackingHoursServiceBinding" maxReceivedMessageSize="2147483647" useDefaultWebProxy="False">
      <readerQuotas maxDepth="32" maxStringContentLength="20000" maxArrayLength="2147483647" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
     <!-- WAS 
     <security mode="None" /> 
     -->
     <security mode="Message">
        <message clientCredentialType="Windows" />
      </security>
    </binding>
  </wsHttpBinding>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_ITFSService" />
  </basicHttpBinding>
</bindings>
<client>
  <endpoint address="http://AAA/TrackingHoursService.svc" binding="wsHttpBinding" bindingConfiguration="TrackingHoursServiceBinding" contract="ITrackingHoursService" name="WSHttpBinding_ITrackingHoursService">
    <identity>
      <dns value="localhost" />
    </identity>
  </endpoint>
  <endpoint address="http://2121212/WSELFO/TFSService.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ITFSService" contract="ITFSService" name="BasicHttpBinding_ITFSService" />
</client>
</system.serviceModel>
System.Net.CredentialCache.DefaultCredentials
System.Net.CredentialCache.DefaultNetworkCredentials