The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:requests. The InnerException message was 'Error in line 1 position 370. Element 'http://schemas.datacontract.org/2004/07/Agatha.Common:Request' contains data from a type that maps to the name 'http://schemas.datacontract.org/2004/07/Sample.Common.RequestsAndResponses:HelloWorldRequest'. The deserializer has no knowledge of any type that maps to this name. Consider using a DataContractResolver or add the type corresponding to 'HelloWorldRequest' to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding it to the list of known types passed to DataContractSerializer.'. Please see InnerException for more details.
new ServiceLayerConfiguration(Assembly.GetExecutingAssembly(), typeof(HelloWorldRequest).Assembly,typeof(Agatha.Castle.Container)).Initialize();
I have developed an WCF Service Library that uses Agatha RRSL, but I can not figure out how to initialize the container. If I recreate this service in an ASP.NET Web Application, I can call the initialization code from the Global.asax.cs Application_Start() and everything works perfectly. The initialization code is:
public static class ComponentRegistration
{
public static void Register()
{
new ServiceLayerConfiguration(Assembly.GetExecutingAssembly(),
typeof(HelloWorldRequest).Assembly,
typeof(Agatha.Castle.Container)).Initialize();
}
}
In the WCF Service Library, I added an App_Code folder with a class that calls:
public static void AppInitialize()
{
ComponentRegistration.Register();
}
That didn't work as my client app throws an exception that there is no response with that type. I also tried adding a component to the web.config file, but I never got that even close to working.
I also tried to create a custom ServiceHost that does the initialization:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ServiceModel;
using System.ServiceModel.Activation;
using Agatha.ServiceLayer;
using System.Reflection;
using Sample.Common.RequestsAndResponses;
namespace Sample.ServiceLayer.WCFHost
{
public class CustomServiceHostFactory : ServiceHostFactory
{
public CustomServiceHostFactory()
{
new ServiceLayerConfiguration(Assembly.GetExecutingAssembly(), typeof(HelloWorldRequest).Assembly,
typeof(Agatha.Castle.Container)).Initialize();
}
protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
{
return new CustomServiceHost(serviceType, baseAddresses);
}
}
public class CustomServiceHost : ServiceHost
{
public CustomServiceHost()
{
}
public CustomServiceHost(Type serviceType, params Uri[] baseAddresses)
: base(serviceType, baseAddresses)
{
}
protected override void OnOpening()
{
base.OnOpening();
}
protected override void OnClosing()
{
base.OnClosing();
}
protected override void ApplyConfiguration()
{
base.ApplyConfiguration();
}
}
}
However, I get the same exception on my client:
System.InvalidOperationException was unhandled
Message=There is no response with type Sample.Common.RequestsAndResponses.HelloWorldResponse. Maybe you called Clear before or forgot to add appropriate request first.
Source=Agatha.Common
StackTrace:
at Agatha.Common.RequestDispatcher.Get[TResponse]() in c:\src\Agatha\Agatha.Common\RequestDispatcher.cs:line 125
at Agatha.Common.RequestDispatcher.Get[TResponse](Request request) in c:\src\Agatha\Agatha.Common\RequestDispatcher.cs:line 150
at ConsoleApplication1.Program.Main(String[] args) in C:\Users\ultraviolet\Documents\Visual Studio 2010\Projects\AgathaHelloWorld\ConsoleApplication1\Program.cs:line 20
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
What approach should I take to get the WCF Service Library to run my initialization code so that the host returns the correct type? Any guidance would be much appreciated. Thanks.