使用json wcf C#服务的jQuery
这就是我的服务的样子。使用json wcf C#服务的jQuery,c#,jquery,asp.net,wcf,C#,Jquery,Asp.net,Wcf,这就是我的服务的样子。 我有一个类和一个接口。我的服务是公开的,我可以通过wcftestClient工具调用它们 我能用jQuery使用这样的web服务吗 我遇到的问题是在jQuery中调用它。它以JSON格式返回。 我在firebug中得到以下错误 状态代码: 未找到HTTP/1.1 404 .cs 接口 [OperationContract] string HelloWorld(); jQuery function GetService() {
我有一个类和一个接口。我的服务是公开的,我可以通过wcftestClient工具调用它们 我能用jQuery使用这样的web服务吗 我遇到的问题是在jQuery中调用它。它以JSON格式返回。 我在firebug中得到以下错误 状态代码: 未找到HTTP/1.1 404 .cs 接口
[OperationContract]
string HelloWorld();
jQuery
function GetService() {
var BizName = $('#txtBizName').val();
//alert(BizName);
$.ajax({
url: "http://www.website.com/WCFService/EdWebService.svc?HelloWorld",
type: "GET",
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function(msg) {
$('#status').html('Output: '+msg['d']['Id']);
},
error: function(e) {
$('#status').innerHTML = "Unavailable";
}
});
alert(BizName);
}
您应该替换
url:“http://www.website.com/WCFService/EdWebService.svc?HelloWorld“
使用url:http://www.website.com/WCFService/EdWebService.svc/HelloWorld“
首先
原因:您没有调用HelloWorld方法,而是将“HelloWorld”作为参数(以非常错误的方式)传递给服务的某个未知方法(我不知道在没有指定方法的情况下哪个方法解析服务名称)
那么它应该会起作用。如果没有,请更新您的问题。我有一个名为HelloWorld的方法,该方法不包含任何参数,并返回字符串“HelloWorld”。我怎么称呼这个?此url显示wsdl,以下url在添加到浏览器url时返回错误400。@Krivahndos请尝试在$ajax调用中更改GET to POST。我提供的URL是正确的,因为错误404(未找到)现在替换为错误400(错误请求)。现在您应该创建正确的请求了。顺便问一下,您的jQuery和WCF服务页面是否在同一个域和端口上?
function GetService() {
var BizName = $('#txtBizName').val();
//alert(BizName);
$.ajax({
url: "http://www.website.com/WCFService/EdWebService.svc?HelloWorld",
type: "GET",
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function(msg) {
$('#status').html('Output: '+msg['d']['Id']);
},
error: function(e) {
$('#status').innerHTML = "Unavailable";
}
});
alert(BizName);
}