Jun 30 2009

Nvigorate Alpha Release 0.8.1.0 – Dynamic WCF Proxy

Category: NvigorateAlexRobson @ 14:45


So today I found a pretty huge error in the guts of Nvigorate. I’m still not clear how I managed to ignore the broken unit tests (sorry all) but now they’re all passing again. The exception occurred when attempting to use Reflector to read/write from static members and was introduced at some point when I added the caching functionality to Reflector (which greatly improves the performance of several things in the framework).

The positive addition to Nvigorate since the last point release is the beginnings of dynamic WCF proxy client(s) called ServiceClient (catchy, right?) My primary reason for creating this is my passionate hatred of SvcUtil and all the little headaches of the code it generates. It’s very new code so you shouldn’t expect a lot of bells and whistles but it does allow you to create WCF service proxies without a lot of overhead. You can choose to configure the client entirely through code, through configuration, or, my personal favorite, from the MEX endpoint of the service itself. The nice thing about that last option is that the binding can change and (most of the time) you won’t have to make changes to your code, the client configures itself based on the metadata it receives from the service.

Here’s a quick example of two ways to use the client

// Very simple service implementation

[ServiceContract]
public interface ITestService
{
    [OperationContract]
    string ReturnString(string input);
}

public class TestService : ITestService
{
    public string ReturnString(string input)
    {
        return input;
    }
}

// ServiceClient's IDisposable implementation provides
// channel management so the channel is properly closed
// and disposed of once you're done with it.

using (var client = new ServiceClient<ITestService>(_address))
{
    var returned = client.Proxy.ReturnString("test");
}


// This approach will open/close/abort the channel
// for the single call. It also provides try/catch/finally
// and logging hooks to provide a slightly more robust user
// experience

using (var client = new ServiceClient<ITestService>(_address))
{
    var returned = client.Call(c => c.ReturnString("test"));
}

Tags:

Comments

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading