Hi all
I'm developing a system that uses the WCF facility. It's a kind of
"plugin" architecture where the client dynamically loads functionality
from external assemblies. It's working - to a point - but I have an
interesting "chicken and egg" problem...
The WCF service provides two operations:-
public string[] GetPluginAssemblyNames()
public bool ExecuteCommand(CommandBase command)
The "CommandBase" class is an abstract base class for various concrete
"command" classes which exist in the various external assemblies that
the client will load. Because I'm using a base class in the WCF
operation I need to register the known types with WCF (i.e. all the
command classes that I might want to send across the wire). To do this
I've written the following class (cut down a little but the essentials
are here):-
public static class KnownTypesProvider
{
public static IEnumerable<Type>
GetKnownTypes(ICustomAttributeProvider provider)
{
return
ServiceLocator.Current.ResolveAll<CommandBase>().Select(o =>
o.GetType());
}
}
I then include this attribute on my service contract to get WCF to use
the above method to retrieve its list of known types:-
[ServiceKnownType("GetKnownTypes", typeof(KnownTypesProvider))]
So the client app goes like this:-
First it calls the GetPluginAssemblyNames() operation to get a list of
assembly names. The client then iterates through these assemblies
registering all components inheriting from CommandBase with Windsor.
This all works fine.
The client app then at some point calls the ExecuteCommand()
operation, passing it one of these command objects. It's here that I
get the standard known types exception: "There was an error while
trying to serialize parameter ... Consider using a
DataContractResolver or add any types not known statically to the list
of known types, etc...".
Using breakpoints I can see that my known types helper method gets
called prior to the client app calling the GetPluginAssemblyNames()
operation. At this point I haven't registered the command classes with
Windsor, so the helper returns an empty list. I'm assuming the WCF
framework caches this list, because the known types helper isn't
called again when the client calls the ExecuteCommand() operation. It
fails because WCF has an empty list of known types.
So my question is this - is there a way of forcing WCF to go and get
the list of known types again? I wasn't sure if it was a lifestyle
thing, so I changed the WCF service to a transient, and tried
releasing it after calling the GetPluginAssemblyNames() operation
(hoping WCF would call my known types helper again before the call to
ExecuteCommand()), but it made no difference. I could have been doing
something wrong though. Alternatively, is there some way to access the
client-side DataContractSerializer, to pass it a list of known types,
or is the serializer hidden away with no public access?
Thanks in advance
Andy
--
You received this message because you are subscribed to the Google Groups
"Castle Project Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/castle-project-users?hl=en.