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

Friday, July 3, 2009

Use of Dataview Find / FindRow OR DataTable Filtering


Some time people will get into confusion of usage and which object need to be used .Most of the time when we are dealing with a set of Data we have to filter the data based on certain criteria.Normally we all are dealing with two objects called DataView and DataTable. Let how these object can support filtering option.

1.Using DataTable

DataRow[] rows = dataTable.Select("Age > '25'", "Eid DESC")

Here you have a datatable in which you are applying filter condition as well as sorting order.

2.Using DataView

dataView.Sort = "ID";
DataRowView[] rows = dataView.FindRows("2500");

Here the limitation is you have to sort based on coloumn then filter based on that coloumn

3.Using DataView with filter Property
Dataset1.Tables[0].DefaultView.RowFilter = "Age > '25'";

Cheers
Shyju Mohan