Blog: WCF

The correct handling of a WCF client’s life cycle

December 21, 2014, (updated on February 25, 2015), Software Development

The most intuitive way of handling a generated WCF client’s life cycle is by putting it into a using block: using (var svc = new MyServiceClient()) { var result = await svc.SumAsync(1, 2); } Note: You should not use static or singleton client objects. However, the problem with this code is, that IDisposable is not implemented correctly in the base class ClientBase. The problem is that the Dispose method always calls Close but Close may throw an exception. If this exception is thrown an additional call to Abort is needed but which is not made. Missing this Abort call may […] Read more...

Tags: , , ,

EF & WCF: Serialize not loaded collection navigation properties as null rather than an empty collection

April 25, 2013, (updated on September 8, 2014), Software Development

Sometimes a web service client wants to know if a collection navigation property (a navigation property with “many” references) of a received entity object has been loaded on the server (e.g. by using Entity Framework’s Include method). By default, not loaded collection navigation properties are serialized as empty collections (not null). This is why the client cannot differentiate between a not loaded property and an empty collection. In one of my projects, I needed to have this information to know if a property is already loaded or has to be lazy loaded using an additional web service call. A way […] Read more...

Tags: , , , ,

Using Entity Framework Code-First proxies with WCF web services

April 30, 2012, (updated on December 21, 2014), 5 comments, Software Development

This blog post demonstrates how to set up a WCF web service together with lazy loading Entity Framework entities. The entities will be developed using a code first approach and their metadata is defined using the fluent API. To use all these features you need to install the newest Entity Framework (version 4.3.1 as of now) as a NuGet package (search for “Entity Framework“). In this blog we will work with a sample persistence model with two entity classes: persons and accounts. There is only one relation: Every person can have multiple accounts. The code of the two persistence classes […] Read more...

Tags: , , , ,

Implement secure WCF web services to use with Windows Phone and Metro style apps

April 30, 2012, (updated on October 20, 2014), 2 comments, Software Development

The first part of this blog post demonstrates how to implement a WCF web service with username/password authentication and role based authorization. The web service can be used in Windows Phone applications and Windows 8 applications and it is even possible to use it with other libraries or frameworks. The second part explains how to set up the development environment to test the web service and the client application locally. The sample project can be downloaded here. Web service code First we have to create a new web service project and create a web service (.svc and its corresponding .svc.cs […] Read more...

Tags: , ,

  Page 1 of 1