涉及到的技术概念 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控制台的调试结果

一个诡异的WCF问题

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

如果修改信息风格为bare 

WebMessageBodyStyle.Bare

connectionconfig不是null但是其属性是null

最终的解决方法

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

一个诡异的WCF问题

一个诡异的WCF问题

后台就不会出现null值

原因不详

 

相关文章:

  • 2021-11-29
  • 2021-08-22
  • 2021-10-02
  • 2021-08-19
  • 2022-02-09
  • 2021-11-06
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-04-05
  • 2022-02-17
  • 2022-12-23
  • 2021-10-12
  • 2021-06-04
  • 2021-07-06
相关资源
相似解决方案