Showing posts with label impersonation in wcf. Show all posts
Showing posts with label impersonation in wcf. Show all posts

Thursday, July 23, 2009

Solving WCF's windows authentication issue in IIS

System.ServiceModel.ServiceHostingEnvironment+HostingManager/27836922
Exception: System.ServiceModel.ServiceActivationException: The service '/internetbanksignon.svc' cannot be activated due to an exception during compilation. The exception message is: Security settings for this service require Windows Authentication but it is not enabled for the IIS application that hosts this service.. --->
in this case you will need to set windows authentication and change the iis metabase manualy
On your IIS server, start Notepad, and then open the \system32\inetsrv\Metabase.xml file located on the hard disk.
In the section, locate the following line:
NTAuthenticationProviders="NTLM"
Modify the line so that it reads exactly as follows:
NTAuthenticationProviders="Negotiate,NTLM"
Check also the attribute of the solution vdir at the metabse.xml.

Tuesday, July 7, 2009

Creating WCF client for asmx wervice and passing default Credential

If you are consuming a asmx service as a WCF client and try to pass the credential to the service you may recieve following error.

The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'Negotiate,NTLM

Reason : WCF uses anonymous authentication, whereas the ASP.Net development web server uses NTLM.

To avoid This error you have to spcify security configuration for wcf client in app.config of client


<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="WebsSoap" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />


<!--keey come here you have to spcify mode as TransportCredentialOnly -->
<security mode="TransportCredentialOnly">
<!--keey come here you have to spcify the clientCredentialType as Ntlm-->
<transport clientCredentialType="Ntlm"/>
</security>
</binding>
</basicHttpBinding>
<client>
<endpoint address="http://litwaredemo:28519/_vti_bin/webs.asmx"
binding="basicHttpBinding" bindingConfiguration="WebsSoap"
contract="SharePointService.WebsSoap" name="WebsSoap" />
</client>
</system.serviceModel>


How to pass Credential

SampleServiceClient sourceService = new SampleServiceClient ();

sourceService.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;

sourceService.ClientCredentials.Windows.ClientCredential = (NetworkCredential) System.Net.CredentialCache.DefaultCredentials;


Cheers
Shyju Mohan