I want to present a solution that works for me.
Editing web.config
First thing is a properly edited web.config file:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | <? xml version = "1.0" ?> < configuration > < connectionstrings > </ connectionStrings > < system.web > < compilation debug = "true" targetFramework = "4.0" /> < authentication mode = "Windows" /> </ system.web > < system.serviceModel > < bindings > < basichttpbinding > < binding name = "Mybinding" > < security mode = "TransportCredentialOnly" > < transport clientCredentialType = "Windows" /> </ security > </ binding > </ basicHttpBinding > </ bindings > < services > < service behaviorConfiguration = "MybehaviorConfig" name = "MyNamespace.MyService" > < endpoint address = "" binding = "basicHttpBinding" bindingConfiguration = "Mybinding" name = "MyEndpoint" contract = "MyNamespace.IMyService" /> </ service > </ services > < behaviors > < servicebehaviors > < behavior name = "MybehaviorConfig" > < servicemetadata httpGetEnabled = "true" /> < servicedebug includeExceptionDetailInFaults = "true" /> </ behavior > </ serviceBehaviors > </ behaviors > </ system.serviceModel > </ configuration > |
Just replace 'service - name' and 'endpoint - contract' attributes values (lines 26, 29) with your specific names.
Configuring service on IIS
Next step is to set Windows Authentication for service in IIS settings. On IIS7 it can be done in following way:- Go to: WebSite - Your service - Authentication:
- Disable Anonumous and all others
- Enable Windows Authentication
- Next click on Windows Authentication and then Providers
- Add Negotiate provider
- An important thing is providers order
- NTLM
- Negotiate
Applying authentication in an application
At your client application add following code so it can authenticate:1 2 3 | MyService ws = new MyService(); ws.Credentials = System.Net.CredentialCache.DefaultCredentials; |
No comments:
Post a Comment