I have a WCF RESTful service which takes JSON as POST/PUT input and I am trying to figure out if the deserialisation of the stream is possible so that it become case-insensitive. So far I have I have done following:
Put a custom host in Global.Asax
Replace the DataContractSerializerOperationBehaviour with my custom Behaviour
I am really not sure how to go about writing the CreateSerialiser to make it case-insensitive. Any help will be tremendously appreciated.
Here is the code in Global.asax:
protected void Application_Start(object sender, EventArgs e)
{
//Other things
RouteTable.Routes.Add(new ServiceRoute("", new MyCustomHostFactory(), typeof(MyService)));
}
public class MyCustomHostFactory : WebServiceHost2Factory //ServiceHostFactory
{
protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
{
return new MyServiceHost(serviceType, baseAddresses);
}
}
public class MyServiceHost : WebServiceHost2
{
public MyServiceHost(Type serviceType, Uri[] baseAddresses)
: base(serviceType, true, baseAddresses)
{
if (Description.Endpoints != null)
{
if (dataContractSerializerElement != null)
{
foreach (var dataContractSerializerOperationBehavior
in
Description.Endpoints.SelectMany(e =>
e.Contract.Operations).Select(op =>
op.Behaviors.Find<MyDataContractSerializerOperationBehaviour>() ??
new MyDataContractSerializerOperationBehaviour(op)))
{
dataContractSerializerOperationBehavior.MaxItemsInObjectGraph =
dataContractSerializerElement.MaxItemsInObjectGraph;
}
}
}
}
}
class MyDataContractSerializerOperationBehaviour : DataContractSerializerOperationBehavior
{
public MyDataContractSerializerOperationBehaviour(OperationDescription operation)
: base(operation)
{
}
public MyDataContractSerializerOperationBehaviour(OperationDescription operation, DataContractFormatAttribute dataContractFormatAttribute)
: base(operation, dataContractFormatAttribute)
{
}
//THIS IS WHERE I AM STUCK
}