Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.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
通过WCF数据服务(Silverlight)获取Windows用户名_Windows_Wcf - Fatal编程技术网

通过WCF数据服务(Silverlight)获取Windows用户名

通过WCF数据服务(Silverlight)获取Windows用户名,windows,wcf,Windows,Wcf,我正在尝试使用WCF数据服务获取silverlight 4应用程序的windows用户名。当我从本地机器调试应用程序时,我看到了用户名。但是当我从web服务器运行应用程序时,用户名显示为空。 如果您需要任何其他详细信息,请告诉我。非常感谢您的帮助 下面是我用来获取用户名的方法: [OperationContract] public string GetWindowsUsername() { string usr = HttpContext.Current.User.Identity.Na

我正在尝试使用WCF数据服务获取silverlight 4应用程序的windows用户名。当我从本地机器调试应用程序时,我看到了用户名。但是当我从web服务器运行应用程序时,用户名显示为空。 如果您需要任何其他详细信息,请告诉我。非常感谢您的帮助

下面是我用来获取用户名的方法:

[OperationContract]
public string GetWindowsUsername()
{
    string usr = HttpContext.Current.User.Identity.Name;
    return usr.ToString();
}
这是我的Web.Config:

    <system.web>
        <compilation debug="true" targetFramework="4.0" />
      <httpRuntime maxRequestLength="2147483647" />
      <authentication mode="Windows" />
      <!--<anonymousIdentification enabled="true"/>-->
      <authorization>
        <allow users="*"/>
      </authorization>
      <!--<identity impersonate="false" />-->
    </system.web>
 <system.serviceModel>
        <behaviors>
            <serviceBehaviors>
                <behavior name="">
                    <serviceMetadata httpGetEnabled="true" />
                    <serviceDebug includeExceptionDetailInFaults="false" />
                    <dataContractSerializer maxItemsInObjectGraph="2147483647" />
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <bindings>
            <basicHttpBinding>
                <binding name="OrderTrackingSystem.Web.OTSService.customBinding0"
                    maxBufferPoolSize="2147483647" maxBufferSize="2147483647"
                    maxReceivedMessageSize="2147483647" transferMode="Streamed">
                    <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
                        maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
                  <security>
                    <transport clientCredentialType="Ntlm" />
                  </security>
                </binding>
            </basicHttpBinding>
        </bindings>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
        <services>
            <service name="OrderTrackingSystem.Web.OTSService">
                <endpoint address="" binding="basicHttpBinding" bindingConfiguration="OrderTrackingSystem.Web.OTSService.customBinding0"
                    name="OTSServiceCustom" contract="OrderTrackingSystem.Web.OTSService" />
            </service>
        </services>
    </system.serviceModel>
<configuration>
  <system.serviceModel> 
    <bindings>
      <basicHttpBinding>
        <binding name="OTSServiceCustom" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" />
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:49458/OTSService.svc" binding="basicHttpBinding"
        bindingConfiguration="OTSServiceCustom" contract="OTSProxy.OTSService"
        name="OTSServiceCustom" />
    </client>
  </system.serviceModel>
</configuration>

这是我的服务配置:

    <system.web>
        <compilation debug="true" targetFramework="4.0" />
      <httpRuntime maxRequestLength="2147483647" />
      <authentication mode="Windows" />
      <!--<anonymousIdentification enabled="true"/>-->
      <authorization>
        <allow users="*"/>
      </authorization>
      <!--<identity impersonate="false" />-->
    </system.web>
 <system.serviceModel>
        <behaviors>
            <serviceBehaviors>
                <behavior name="">
                    <serviceMetadata httpGetEnabled="true" />
                    <serviceDebug includeExceptionDetailInFaults="false" />
                    <dataContractSerializer maxItemsInObjectGraph="2147483647" />
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <bindings>
            <basicHttpBinding>
                <binding name="OrderTrackingSystem.Web.OTSService.customBinding0"
                    maxBufferPoolSize="2147483647" maxBufferSize="2147483647"
                    maxReceivedMessageSize="2147483647" transferMode="Streamed">
                    <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
                        maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
                  <security>
                    <transport clientCredentialType="Ntlm" />
                  </security>
                </binding>
            </basicHttpBinding>
        </bindings>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
        <services>
            <service name="OrderTrackingSystem.Web.OTSService">
                <endpoint address="" binding="basicHttpBinding" bindingConfiguration="OrderTrackingSystem.Web.OTSService.customBinding0"
                    name="OTSServiceCustom" contract="OrderTrackingSystem.Web.OTSService" />
            </service>
        </services>
    </system.serviceModel>
<configuration>
  <system.serviceModel> 
    <bindings>
      <basicHttpBinding>
        <binding name="OTSServiceCustom" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" />
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:49458/OTSService.svc" binding="basicHttpBinding"
        bindingConfiguration="OTSServiceCustom" contract="OTSProxy.OTSService"
        name="OTSServiceCustom" />
    </client>
  </system.serviceModel>
</configuration>

我试图创建一个演示应用程序来测试东西,下面的内容对我来说很有用

[OperationContract]
public string GetWindowsUsername()
{
    string usr = ServiceSecurityContext.Current.WindowsIdentity.Name;
    return usr;
}
但为了实现这一点,您必须将绑定配置为:

<bindings>
   <basicHttpBinding>
        <binding name="OTSServiceCustom">
           <security mode="TransportCredentialOnly">
                <transport clientCredentialType="Ntlm" proxyCredentialType="None" />
           </security>
    </binding>
  </basicHttpBinding>
</bindings>


希望这有助于…

检查这一点,因为我不寻求身份验证,所以它对我不起作用。我只需要windows用户名,我还看了另一篇文章。我得到的当前值为空。我尝试过,它在web应用程序中询问用户名和密码。我通过在身份验证方法中禁用匿名访问来尝试。非常感谢您的尝试。您对web应用程序使用的身份验证是什么?Asp Net表单身份验证?您的web应用也必须使用NTLM,否则您如何知道windows用户正在登录?您必须启用模拟。检查