Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
173 views
in Technique[技术] by (71.8m points)

c# - WCF Service, Windows Authentication

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?

Thanks in advance,

Ashish

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You have to do a few things:

  • 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>
    
  • 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>
    
    • 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();
      

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"


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...