Odata Query with DataServiceContext and get the result as json

I have a DataServiceContext requesting my WCF data service:

service = new DataServiceContext(new Uri(SvcUrl)); service.SendingRequest += new EventHandler<SendingRequestEventArgs> (OnSendingRequest); 

I want to set the Accept header to get the result as json:

  static void OnSendingRequest(object sender, SendingRequestEventArgs e) { e.RequestHeaders.Set("Accept", "json/text"); } 

But I get an exception:

"This header must be modified using the appropriate property or method. Parameter name: name"

I cannot figure out how else to set the Accept header.

+2
source share
1 answer

Boooo hoo ... just found this msdn thread .

The answer there says:

β€œSince the client code is not written to handle the json response, we do not allow Accept headers to be overloaded. It is best to use HttpWebRequest directly and then process the json response yourself.

+2
source

Source: https://habr.com/ru/post/947087/


All Articles