How do I create a dynamic response with out using the query string?
I want to dynamically output the response format based on what the user specifics inside of the message body.
For example, if the user inputs "json","xml","soap", it will return the respective format. Thanks, in advance.
public interface IReg
{
[OperationContract]
[WebInvoke]
MemberBasic Login(string uniqueID, string password, string returnFormat);
}
[DataContract(Namespace = "", IsReference=false)]
[Serializable()]
public class MemberBasic
{
#region Properties
[DataMember]
public DateTime LastModified
{
get;
set;
}
}
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
public sealed class RWS : IReg
{
public MemberBasic Login(string uniqueID, string password, string returnFormat)
{
MemberBasic result = new MemberBasic();
setReturnFormat(returnFormat);
return result;
}
}
private static void Init(string returnFormat)
{
var response = WebOperationContext.Current.OutgoingResponse;
response.Headers.Add("cache-Control", "no-cache");
response.Headers.Add("Last-Modified", string.Format("{0:r}", DateTime.Today));
switch (returnFormat)
{
case "xml":
{
WebOperationContext.Current.OutgoingResponse.Format = WebMessageFormat.Xml;
WebOperationContext.Current.OutgoingRequest.Headers.Add(System.Net.HttpRequestHeader.ContentType, "application/json");
} break;
case "json":
{
WebOperationContext.Current.OutgoingResponse.Format = WebMessageFormat.Json;
} break;
default:
{
throw new ArgumentException("Return Format unrecognized; cannot complete request.",
"returnFormat");
}
}
}