Part -1
public class HttpMessageFormatter : IDispatchMessageFormatter
{
public IDispatchMessageFormatter XmlRequestFormatter
{
get;
set;
}
public IDispatchMessageFormatter JsonRequestFormatter
{
get;
set;
}
public IDispatchMessageFormatter XmlResponseFormatter
{
get;
set;
}
public IDispatchMessageFormatter JsonResponseFormatter
{
get;
set;
}
public void DeserializeRequest(System.ServiceModel.Channels.Message message, object[] parameters)
{
if (message == null)
return;
IDispatchMessageFormatter formatter = JsonRequestFormatter;
string contentType = WebOperationContext.Current.IncomingRequest.ContentType;
if (contentType != null)
{
contentType = contentType.ToLower();
if (contentType.Contains("text/xml") || contentType.Contains("application/xml") )
{
formatter = XmlRequestFormatter;
}
}
try
{
formatter.DeserializeRequest(message, parameters);
}
catch (System.Runtime.Serialization.SerializationException exp)
{
throw new RequestSerializationException( "Error in request de-serialization" , exp );
}
}
public System.ServiceModel.Channels.Message SerializeReply(System.ServiceModel.Channels.MessageVersion messageVersion, object[] parameters, object result)
{
IDispatchMessageFormatter formatter = JsonResponseFormatter;
string contentType = WebOperationContext.Current.IncomingRequest.ContentType;
if (contentType != null)
{
contentType = contentType.ToLower();
if (contentType.Contains("text/xml") || contentType.Contains("application/xml"))
{
formatter = XmlResponseFormatter;
}
}
return formatter.SerializeReply(messageVersion, parameters, result);
}
Wednesday, April 14, 2010
Subscribe to:
Posts (Atom)