WCF - 通过POST使用JSON参数 [英] WCF - Consuming JSON parameters through a POST

查看:378
本文介绍了WCF - 通过POST使用JSON参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以帮我确定为什么我的包装JSON参数为NULL吗?



我正在尝试将供应商的产品集成到我们的产品中内部软件并创建了一个WCF Web服务来处理他们的POST请求。



请求主体中供应商的JSON数据格式如下所示:

{Call:{call_detail_id:3514736,ouid:7425}}



如果我创建测试界面使用WebMessageBodyStyle.Bare并传入几个JSON参数,它工作得很好。然而,供应商的键入的JSON没有通过。



任何帮助都将非常感激。



谢谢,





Andre Ranieri





Can anyone please help me determine why my wrapped JSON parameters are coming in NULL?

I''m trying to integrate a vendor''s product into our internal software and have created a WCF web service to handle their POST requests.

The vendor''s JSON data format in the request body look like this:
{ "Call": { "call_detail_id": "3514736", "ouid": "7425" } }

If I create a test interface with WebMessageBodyStyle.Bare and pass in a couple JSON parameters, it works great. However, the vendor''s typed JSON is not coming through.

Any help would be very much appreciated.

Thanks,


Andre Ranieri


[ServiceContract]
    public interface IMyService    
{
        [OperationContract]
        [WebInvoke(
               Method = "POST", 
               UriTemplate = "post-call/",
               RequestFormat = WebMessageFormat.Json, 
               ResponseFormat = WebMessageFormat.Json,
               BodyStyle = WebMessageBodyStyle.WrappedRequest
               )
        ]
        string lmc_BusinessLogic(Call myCall);

    }


    public class Call
    {
        [DataMember(Name = "call_detail_id")]
        public string call_detail_id { get; set; }
        [DataMember(Name = "ouid")]
        public string ouid { get; set; }

    }







实施:






Implementation:

public string lmc_BusinessLogic(Call myCall)
        {
            // myCall object is null when passed in here.
            // Implement some business logic once the parms are getting passed.

        }

推荐答案

BodyStyle = WebMessageBodyStyle.WrappedRequest to BodyStyle = WebMessageBodyStyle.Bare



也改变


also change

{ "Call": { "call_detail_id": "3514736", "ouid": "7425" } } to { "myCall": { "call_detail_id": "3514736", "ouid": "7425" } }



希望这有助于


Hope this helps


这篇关于WCF - 通过POST使用JSON参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆