Odata Query with DataServiceContext and get result as json

↘锁芯ラ 提交于 2019-12-24 02:30:16

问题


I have a DataServiceContext querying my WCF Data Service:

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

I want to set the Accept header so that I 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 seem to figure out how else to set the Accept header.


回答1:


Boooo hoo... just found this msdn thread.

The answer there says :

"Since the client code is not written to handle json response, we don't allow Accept headers to be over-ridden. Your best bet would be to use HttpWebRequest directly and then handle the json response yourself."



来源:https://stackoverflow.com/questions/5414360/odata-query-with-dataservicecontext-and-get-result-as-json

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!