从jso获取通过JavaScript发布的数据/正文

时间:2018-07-03 03:42:41

标签: c# wcf service

我有以下内容:

[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, UriTemplate = "does/work")]
        public bool DoesWork() {
            bool Success = false;

            IncomingWebRequestContext woc = WebOperationContext.Current.IncomingRequest;


            return Success;
        }

我可以通过POSTMAN成功发布,但无法获取以原始文本形式放置在正文中的json,如何在c#中以字符串形式获取数据?

谢谢

1 个答案:

答案 0 :(得分:1)

尽管您在Post请求的正文中发送参数值,但是您需要通过方法parameter接受参数值。只需向您的方法添加参数,它就可以解决您的问题。

[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, UriTemplate = "does/work")]
    public bool DoesWork(WorkDetails workDetails) {
        bool Success = false;
        var work = worDetails.something; //if the type matches with your json content, you should have the values populated under work details
        IncomingWebRequestContext woc = WebOperationContext.Current.IncomingRequest;


        return Success;
    }