2012-09-24 128 views
2

在我的一个应用程序中,我通过Windows帐户连接和验证WCF服务时遇到问题。为了测试这一点,我已经将它转变为一个简单的控制台应用程序和VS2010中的标准WCF启动应用程序的新解决方案。WCF Windows身份验证,未通过

WCF代码,一个简单的动作:

[PrincipalPermission(SecurityAction.Demand, Role = "xxxx\\xxxxxx")] 
    public string GetData(int value) 
    { 
     return string.Format("You entered: {0}", value); 
    } 

配置文件:

<bindings> 
     <basicHttpBinding> 
      <binding name="BasicHttpBinding_IService1"> 
      <security mode="TransportCredentialOnly"> 
       <transport clientCredentialType="Windows" proxyCredentialType="Windows"/> 
       <message clientCredentialType="UserName" algorithmSuite="Default"/> 
      </security> 
      </binding> 
     </basicHttpBinding> 
    </bindings> 
    <client> 
     <endpoint address="http://localhost:16674/Service1.svc" binding="basicHttpBinding" 
      bindingConfiguration="BasicHttpBinding_IService1" contract="testService.IService1" 
      name="BasicHttpBinding_IService1" /> 
    </client> 

和呼叫这样:

testService.Service1Client sv = new testService.Service1Client(); 
sv.GetData(1); 

我得到的标准“请求主体许可失败。“错误,虽然我看不到配置文件是错误的。在创建服务对象时,我查看了服务对象,并且ClientCredentials.Windows和username对象为空。任何人都可以帮助我,我在这里是愚蠢的吗?

感谢

回答

0

您需要使用代码来设置凭据,请参阅本article

testService.Service1Client sv = new testService.Service1Client(); 
sv.ClientCredentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultCredentials; 
sv.GetData(1); 
+2

我认为那篇文章可能会过时,但我发现下面 sv.ClientCredentials.Windows .ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials; 但DefaultNetworkCredentials对象是空的? – nik0lias

+0

我更新了代码,您是否尝试过运行它?你仍然得到认证错误?如果我没有记错信用只看起来空... –

+0

看到这个链接重新空凭证http://stackoverflow.com/a/7805911/1045728 –