Post Json to Rest which listen inside a Windows Service

  • Thread starter Thread starter want 2 Learn
  • Start date Start date
W

want 2 Learn

Guest
I have a method inside a Windows Service, when I send a GET all works fine.

I am trying to send post :

on windows service :

[OperationContract]
[WebInvoke(Method = "POST", RequestFormat= WebMessageFormat.Json, UriTemplate = "SendFlash")]
void SendFlash(string data);

from another application which send the json :


//SendURL-->http://localhost/Service

HttpClient httpClient = new HttpClient()
{
BaseAddress = new Uri(ConfigurationManager.AppSettings["SendURL"].ToString())
};

_httpClient .DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
//httpMessages is a List<T> of classes
string data = JsonConvert.SerializeObject(httpMessages);
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "/SendFlash");
request.Content = new StringContent(data,Encoding.UTF8,"application/json");

using (HttpResponseMessage result = await _client.SendAsync( request))
{
if (result.StatusCode == HttpStatusCode.OK)
{ }
else//result.StatusCode
{ }
}




i can't find what i am mising to make it work.

any inputs what can be wrong?


**also I see that in the header there is 3 times application/json (and I wanted to add charset=utf-8)

1552039.png

Continue reading...
 
Back
Top