使用JavaScript的WCF服务 [英] WCF Services using JavaScript
本文介绍了使用JavaScript的WCF服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在本地主机上有一个正在运行的WCF服务,我想从他们调用一个简单的添加方法,但是当我执行以下搜索代码时,它返回null
var baseUrl = < span class =code-string> http:// localhost:49997 / SMD_WCFService / Service.svc?wsdl;
function sendData(){
var json = ' {result:{n1:' + 1 + ' ' + ' ,n2:' + 2 + ' }}';
$ .ajax(
{
type: POST ,
contentType: application / json; charset = utf-8 ,
url:baseUrl,
data:json,
dataType: json ,
成功:功能(数据){alert(data)},
错误: function (){alert( not done)}
});
// 另一种服务方法
var service = new Service.SMDService();
var result = service.Add( 1 , 2 跨度>);
alert(result);
}
解决方案
.ajax(
{
type: POST,
contentType: application / json; charset = utf-8,
url:baseUrl,
data:json,
dataType: json,
成功: function (data){警报(数据)},
错误: function (){alert( 未完成)}
});
// 另一种服务方法
var service = new Service.SMDService();
var result = service.Add( 1 , 2 跨度>);
alert(result);
}
使用Jquery / JavaScript调用跨域WCF服务 [ ^ ]
使用ASP.NET AJAX在JavaScript中使用WCF服务的初学者指南 [ ^ ]
I have a running WCF Service on my local host and I want to call a simple add method from their but as I do the following search codes it returns null
var baseUrl = "http://localhost:49997/SMD_WCFService/Service.svc?wsdl";
function sendData() {
var json = '{"result":{"n1":"' + 1 + '"' + ', "n2":"' + 2 + '"}}';
$.ajax(
{
type: "POST",
contentType: "application/json; charset=utf-8",
url: baseUrl,
data: json,
dataType: "json",
success: function (data) { alert(data) },
error: function () { alert("not done") }
});
// Another Serched Method
var service = new Service.SMDService();
var result = service.Add(1, 2);
alert(result);
}
解决方案
.ajax( { type: "POST", contentType: "application/json; charset=utf-8", url: baseUrl, data: json, dataType: "json", success: function (data) { alert(data) }, error: function () { alert("not done") } }); // Another Serched Method var service = new Service.SMDService(); var result = service.Add(1, 2); alert(result); }
Calling Cross Domain WCF service using Jquery/JavaScript[^]
A beginner’s guide for consuming a WCF service in JavaScript using ASP.NET AJAX[^]
这篇关于使用JavaScript的WCF服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文