将JSON对象传递给WCF服务 [英] pass JSON object to WCF service

查看:101
本文介绍了将JSON对象传递给WCF服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我想将JSON对象传递给WCF服务,

这是我的服务方式:

Hi All,

I want to pass JSON Object to WCF service,
Here is my service method:

[OperationContract]
       [WebInvoke(Method="POST", RequestFormat=WebMessageFormat.Json,     ResponseFormat=WebMessageFormat.Json,        UriTemplate = "/UplodImageAndroid")]
       bool uploadImageAndroid(CustomImage custImg);







public bool uploadImageAndroid(CustomImage custImg)
        {
// logical stuf
}





来自jquery的电话:





Calling from jquery :

$(document).ready(function(){
$("#GetUserDetails").click(function(){

var searchRequest = new Object(); 
    searchRequest.fileName = "Chris";  

		$.ajax({
			type:"POST",
			url:"http://localhost/TestAndroidWcfService/Service1.svc/UplodImageAndroid",
			ProcessData:false,			
			contentType:"application/json;charset=utf-8",
			dataType:"json",
			data:searchRequest,			
			success:function(data){
			alert("Success:"+ data);
			},
			error:function(xhr,status,error){
			alert("Error"+error);
			}
		});
		alert("Hi2");
	});
});







这里我收到错误消息为Bad Request !! < br $> b $ b

如何使它工作?代码有什么错误?



请建议。



谢谢

Avinash




Here I am getting error message as Bad Request!!

How to make it work? What is the mistake in code?

Please suggest.

Thanks
Avinash

推荐答案

(document).ready(function(){
(document).ready(function(){


(#GetUserDetails)。click(function) (){

var searchRequest = new Object();
searchRequest.fileName =Chris;
("#GetUserDetails").click(function(){ var searchRequest = new Object(); searchRequest.fileName = "Chris";


.ajax({
键入:POST,
url:http://localhost/TestAndroidWcfService/Service1.svc/UplodImageAndroid,
ProcessData:false,
contentType:application / json; charset = utf -8,
dataType:json,
data:searchRequest,
success:function(data){
alert(Success:+ data);
},
错误:函数(xhr,状态,错误){
alert(错误+错误);
}
});
alert( Hi2);
});
});
.ajax({ type:"POST", url:"http://localhost/TestAndroidWcfService/Service1.svc/UplodImageAndroid", ProcessData:false, contentType:"application/json;charset=utf-8", dataType:"json", data:searchRequest, success:function(data){ alert("Success:"+ data); }, error:function(xhr,status,error){ alert("Error"+error); } }); alert("Hi2"); }); });







这里我收到错误消息为错误请求!!



如何使它工作?代码有什么错误?



请建议。



谢谢

Avinash




Here I am getting error message as Bad Request!!

How to make it work? What is the mistake in code?

Please suggest.

Thanks
Avinash


这篇关于将JSON对象传递给WCF服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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