views:

385

answers:

4

I have a wcf service for which I am not using a service reference. The classes and interfaces are defined in a dll both the client server reference. Communication with the server uses a class derived from ClientBase.

I want to intercept wcf's default objects creation on the client side, so that I can provide a subtype that implements INotifyPropertyChanged(created by castle dynamic proxy).

Basically the same idea behind NHibernate returning a class implementing INotifyPropertyChanged only for wcf.

+1  A: 

I don't totally understand what you are trying to do - you want to send a POCO from the server to the client: this means, you need to create that POCO class and decorate it as [DataContract], and decorate its members that you want to have serialized with [DataMember].

On the client side, you'll get a client-side proxy class generated that has the same serialized wire format - but since WCF serializes using XML schema as the lowest common denominator, you cannot send around stuff like interfaces and so on - only concrete instance classes. And on the client, you don't get the same class as on the server - just one that has the same "look and feel" (and serialization format).

So I don't really see how and where you want to hook into.

One thing you might do is create a client-side message inspector based on

public interface IClientMessageInspector
{
    void AfterReceiveReply(ref Message reply, object correlationState);
    object BeforeSendRequest(ref Message request, IClientChannel channel);
}

that would catch the "AfterReceiveReply" event, and then you'd take the serialized POCO class coming across the wire, and convert that into another class which would also implement the INotifyPropertyChanged handlers.

See some blog posts on how to write and deal with Message inspectors in WCF:

marc_s
A: 

Are you talking about intercepting the object that CreateChannel from your ChannelFactory spins up?

You could override the BaseChannelFactory and amend it's ClientBase object it returns?

MattC
A: 

Microsoft's SVCUTIL.EXE can automatically generate your proxy data classes with INotifyPropertyChanged properly implemented. Look at the enableDataBinding parameter. It's not exactly what you are asking for, but might solve your needs anyway.

chilltemp
A: 

Have a look at the Castle WCF facility. I am pretty sure you can extend it to add the INotifyPropertyChanged. The facility uses DynamicProxy to generate your proxies.

http://www.castleproject.org/container/facilities/trunk/wcf/index.html

Cosmin Onea