WCF问题

涉及到的技术概念 WCF,REST,AJAX,JSON

遇到的问题:前台页面使用ajax请求后台rest服务,get请求没有问题,post请求时,后台接收参数总是null

rest方法属性,请求参数和返回参数都是json格式

复制代码
#region  创建数据库配置
        /// <summary>
        /// 创建数据库配置
        /// </summary>
        /// <param name="connectionconfig">connectionconfig表实体</param>
        /// <returns>返回受影响行数</returns>
        [OperationContract]
        [WebInvoke(Method = "POST", UriTemplate = "CreateConnectionConfig", BodyStyle = WebMessageBodyStyle.Wrapped,RequestFormat=WebMessageFormat.Json,ResponseFormat=WebMessageFormat.Json)]
        public bool CreateConnectionConfig(ConnectionConfig connectionConfig)
        {
           ...

        }
#endregion
复制代码

chome控制台的调试结果

问题表现在 connectionconfig接收值总是null

如果修改信息风格为bare 

WebMessageBodyStyle.Bare

connectionconfig不是null但是其属性是null

最终的解决方法

将json值得connectionconfig 与rest方法的参数名称connectionConfig一致,主要是大小写一致

后台就不会出现null值

原因不详

 
 
 
标签: wcfrest
原文地址:https://www.cnblogs.com/Leo_wl/p/2846847.html