无法在调试模式下在WCF服务中获取发布的数据.... [英] Unable to get posted data in WCF service in debug mode....

查看:77
本文介绍了无法在调试模式下在WCF服务中获取发布的数据....的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我写了一个简单的HTML页面,我将JSON对象传递给WCF服务。当我在调试模式(VS2012)中运行服务并从IE 10调用页面时,调试器被调用,但在参数中,传递的对象为null ..



< b> jQuery代码:

Hi,
I have written a simple HTML page where I am passing JSON object to WCF service. When I run the service in debug mode (VS2012) and call the page from IE 10, Debugger gets called but in a parameter place object passed is null..

jQuery Code:

var objJSON = {
   "postJSON": {
      "id": "0",
      "emp_name": "abc",
      "emp_city": "delhi",
      "emp_addr": "india"
   }
};

$.ajax({
   type: "POST",
   url: "http://localhost:8080/MainService.svc/updatedata",
   data: JSON.stringify(objJSON),
   dataType: "json",
   contentType: "application/json; charset=utf-8",
   processData:true,
   success: function (objSuccess) {
      console.log("success");
      console.log(JSON.stringify(objSuccess));
   }
   ,
   error: function (objError) {
      console.log("error");
      alert(JSON.stringify(objError));
   }
});





WCF服务代码:



MainService.svc.cs



WCF Service Code:

MainService.svc.cs

public ClsEmployee UpdateEmployee(ClsEmployee objEmployee)
{
   new ClsTransaction().updateRecord(objEmployee);





服务合同



Service Contract

[OperationContract]
   [WebInvoke(Method = "POST", 
      ResponseFormat = WebMessageFormat.Json, 
      RequestFormat = WebMessageFormat.Json, 
      BodyStyle = WebMessageBodyStyle.Wrapped, 
      UriTemplate = "updatedata")]
   ClsEmployee UpdateEmployee(ClsEmployee postJSON);
}

推荐答案

.ajax({
type: POST
url: http:// localhost:8080 / MainService.svc / updatedata
data:JSON.stringify(objJSON),
dataType: json
contentType: application / json; charset = utf-8
processData:true,
success:function(objSuccess){
console.log( success);
console.log(JSON.stringify(objSuccess));
}

错误:function(objError){
console.log( error );
alert(JSON.stringify(objError));
}
});
.ajax({ type: "POST", url: "http://localhost:8080/MainService.svc/updatedata", data: JSON.stringify(objJSON), dataType: "json", contentType: "application/json; charset=utf-8", processData:true, success: function (objSuccess) { console.log("success"); console.log(JSON.stringify(objSuccess)); } , error: function (objError) { console.log("error"); alert(JSON.stringify(objError)); } });





WCF服务代码:



MainService.svc.cs



WCF Service Code:

MainService.svc.cs

public ClsEmployee UpdateEmployee(ClsEmployee objEmployee)
{
   new ClsTransaction().updateRecord(objEmployee);





服务合同



Service Contract

[OperationContract]
   [WebInvoke(Method = "POST", 
      ResponseFormat = WebMessageFormat.Json, 
      RequestFormat = WebMessageFormat.Json, 
      BodyStyle = WebMessageBodyStyle.Wrapped, 
      UriTemplate = "updatedata")]
   ClsEmployee UpdateEmployee(ClsEmployee postJSON);
}


这篇关于无法在调试模式下在WCF服务中获取发布的数据....的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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