Development With A Dot

Blog on development in general, and specifically on .NET

Sponsors

News

My Friends

My Links

Permanent Posts

Portuguese Communities

November 2009 - Posts

Windows Identity Framework Released

Good news: WIF was released today!

Bad news: it requires Windows 7 or Windows Server 2008...

Get it here and the SDK here.

If you just want to know what it is, read this.

Bookmark and Share
Debugging ADO.NET/WCF Data Services

Debugging ADO.NET (now WCF) Data Services can be tricky, not because of the web service part but because of the underlying persistence layer.

You can include the exception details on the error page by including this on the DataService<T> class declaration:

[ServiceBehavior(IncludeExceptionDetailInFaults = true)]
public class MyService: DataService<MYENTITIES>

Alternatively, you can configure it through the Web.config file (all services, only .NET 4):

<serviceBehaviors>
    <behavior name="">
        <serviceMetadata httpGetEnabled="true" /> 
        <serviceDebug includeExceptionDetailInFaults="true" /> 
    </behavior> 
</serviceBehaviors>

Next, you must enable verbose errors on the service configuration:


public static void InitializeService(IDataServiceConfiguration config)
{
config.UseVerboseErrors = true;
}

Also, you can override HandleException method:

protected override void HandleException(HandleExceptionArgs args)
{
base.HandleException(args);
}

This method is called first when an exception occurs but before it propagates to the point of crashing.

Last, you can enable the WCF logging support (more info here:


<system.diagnostics>
  <sources> 
    <source name="System.ServiceModel.MessageLogging" switchValue="Warning, ActivityTracing"> 
      <listeners> 
        <add name="ServiceModelTraceListener"/> 
      </listeners> 
    </source>
    <source name="System.ServiceModel" switchValue="Verbose,ActivityTracing"> 
      <listeners> 
        <add name="ServiceModelTraceListener"/> 
      </listeners> 
    </source> 
    <source name="System.Runtime.Serialization" switchValue="Verbose,ActivityTracing"> 
      <listeners> 
        <add name="ServiceModelTraceListener"/> 
      </listeners> 
    </source> 
  </sources> 
  <sharedListeners> 
    <add initializeData="tracelog.svclog" 
                                    type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" 
                                    name="ServiceModelTraceListener" traceOutputOptions="Timestamp"/> 
  </sharedListeners> 
</system.diagnostics>

Bookmark and Share
ADO.NET Data Service Interceptors

There are two possible interceptions you can perform on an ADO.NET Data Service:

  • Query interception: intercept a query made for an entity in order to enforce a restriction;
  • Change interception: intercept a request for updating an entity and possibly cancel it, or change the entity.

Query interceptions are achieved by marking a method with attribute [QueryInterceptor]; the method must have the following signature:

[QueryInterceptor("Author")]
public Expression<Func<Author, Boolean>> OnFilterAuthor()
{
    return (author => author.Name == "Ricardo Peres");
}

Regardless of the query that you specify on the client proxy or the URL, this restriction is always enforced. The name and visibility are ignored.

Interception queries, on the other hand, allow you to change the entity that is being submitted for persistence, or cancel the operation totally. Decorate a method with a [ChangeInterceptor] attribute and add this arguments:

[ChangeInterceptor("Author")]
public void OnChangeAuthor(Author author, UpdateOperations operations)
{
    if (operations == UpdateOperations.Add)
    {
nbsp;       author.Name = "Ricardo Peres";
    }}

Once again, the visibility and name do not count.

If you want to have restrictions based on the caller's identity (HttpContext.Current.User), you must enable ASP.NET compatibility mode:

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
public class MyDataContext: DataService<MyEntities>

And also enable it on the Web.config:


<system.serviceModel>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
    </system.serviceModel>

Bookmark and Share
NHibernate 2.1.1 Released

Get it here.

Intersting to note, the API documentation is now available in CHM format.

Bookmark and Share
More Posts