WCF服务,Windows身份验证 [英] WCF Service, Windows Authentication

查看:70
本文介绍了WCF服务,Windows身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们编写了一个部署在IIS上的WCF服务.我们选择了集成Windows身份验证.在这种情况下不能使用service服务,但是如果我们可以将WCF服务的IIS虚拟目录的身份验证方法设置为匿名",则该错误将消失.但是,对于我们的WCF服务,匿名"是不可接受的.我们必须使用集成Windows身份验证来验证客户端.有人知道如何解决此问题吗?

we wrote a WCF service, deployed on IIS. we chose Integrated Windows Authentication. service can not be used in this case but if we can set the authentication method of the IIS virtual directory to "Anonymous" for WCF services, then the error will go away. But "Anonymous" is not acceptable for our WCF service. We have to use Integrated Windows Authentication to authenticate the client. Any one knows how to fix this problem?

预先感谢

阿什什

推荐答案

您必须做一些事情:

  • 取消选中来自Virtual Fordder的匿名访问,然后选中Integrated Windows安全性.
  • 创建以下绑定配置:

  • Uncheck the anonymous access from your Virtual forlder and check Integrated windows security.
  • Create the following binding configuration:

  <basicHttpBinding>
 <binding name="Binding1">
    <security mode="TransportCredentialOnly">
        <transport clientCredentialType="Windows"  />
    </security>
 </binding>
 </basicHttpBinding>

  • 将上述配置应用于您的服务和mex:

  • Apply the above configuration to your service and mex:

       <endpoint address="" binding="basicHttpBinding" bindingConfiguration="Binding1" contract="IService">
    </endpoint>
    
    
       <endpoint address="mex" binding="basicHttpBinding" bindingConfiguration="Binding1" contract="IMetadataExchange">
    </endpoint>
    

    • 创建一个客户端并使用NetworkCredential传递您的凭据:

      • Create a client and use NetworkCredential to pass your credentials:

               ServiceReference.MyClient proxy = new ServiceReference.MyClient();
               proxy.ClientCredentials.Windows.ClientCredential = new System.Net.NetworkCredential("MACHINENAME\\USERACCOUNT", "passwrd");
               proxy.YourServiceOperation();
        

      • 还有其他设置用户名&的方法.密码,但在.Net 4.0中不起作用.USERACCOUNT是您的WCF主机已加入的域帐户或LDAP.如果服务器未加入域,则通过运行"lusrmgr.msc"在本地创建帐户

        There are other ways to set username & password indivdually but it didn't work in .Net 4.0. USERACCOUNT is a domain account or LDAP to which your WCF host computer is joined to. If server isnt joined to a domain then create an account locally by running "lusrmgr.msc"

        这篇关于WCF服务,Windows身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆