I have created a web service using .Net 4.5 and RestSharp. The service will initially have two clients that will be consuming it: one that is also using .Net 4.5 and RestSharp and the other is stuck on .Net 2.0 and WebClient (since RestSharp doesn't support .Net 2.0) for the time-being.
I can successfully respond to calls from the .Net 4.5 client with the following action:
[HttpPost]
public IRestResponse<CustomMessageResponseType> Send([FromBody]string message)
{
//action code here;
}
However, this results in message
having a null
value when called by the .Net 2.0 client. I was able to successfully respond to calls from the .Net 2.0 client by changing the action signature to (notice the change in type of the message parameter):
[HttpPost]
public IRestResponse<CustomMessageResponseType> Send([FromBody]CustomMessageType message)
{
//action code here;
}
But this causes a null
value for message
when called by the .Net 4.5 client.
I have also tried having both actions included in the controller and relying on the signature to differentiate between them automatically but this resulted in neither being called.
In the .Net 2.0 client, I am calling the service like this:
private string Send(CustomMessageType message)
{
var request = new WebClient { BaseAddress = API.ToString(), Encoding = Encoding.UTF8 };
request.Headers[HttpRequestHeader.ContentType] = "application/json";
request.Headers[HttpRequestHeader.Accept] = "application/json";
var content = JsonConvert.SerializeObject(message);
var response = request.UploadString("Message", content);
return response;
}
and message contains something like the following:
{
"Subject":"Test Message",
"Body":"This is a test message.",
"Recipients":
[{
"FirstName":"John",
"LastName":"Doe",
"Name":"John Doe",
"RecipientID":"1",
"ContactPoints":
{
"Email":"John.Doe@example.com",
"Phone":null,
"Text":null
}
}],
"Sender":
{
"FirstName":"Test Account",
"LastName":null,
"Name":"Test Account",
"RecipientID":null,
"ContactPoints":
{
"Email":null,
"Phone":"5555551234",
"Text":null
}
}
}
Can anyone help me figure out how to serve both clients?