Is there any way to call web services from javascript? I know you can add in a script manager to pull in the web services but I can't figure out how to access the functions from javascript once I've done that.
有没有办法从JavaScript调用Web服务?我知道你可以添加一个脚本管理器来引入Web服务,但是一旦我完成了,我就无法弄清楚如何从javascript访问这些函数。
Thanks,
Matt
谢谢,马特
2 个解决方案
#1
11
Please see Calling Web Services from Client Script in ASP.NET AJAX:
请参阅ASP.NET AJAX中从客户端脚本调用Web服务:
This topic explains how to use to call a Web service from ECMAScript (JavaScript). To enable your application to call ASP.NET AJAX Web services by using client script, the server asynchronous communication layer automatically generates JavaScript proxy classes. A proxy class is generated for each Web service for which an
<asp:ServiceReference>
element is included under the<asp:ScriptManager>
control in the page.本主题说明如何使用ECMAScript(JavaScript)调用Web服务。为了使您的应用程序能够使用客户端脚本调用ASP.NET AJAX Web服务,服务器异步通信层会自动生成JavaScript代理类。为每个Web服务生成一个代理类,其中
元素包含在页面中的 :servicereference>控件下。 :scriptmanager>
#2
2
See Using jQuery to Consume ASP.NET JSON Web Services by Dave Ward.
请参阅Dave Ward使用jQuery来使用ASP.NET JSON Web服务。
$(document).ready(function() {
$.ajax({
type: "POST",
url: "RSSReader.asmx/GetRSSReader",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
// Hide the fake progress indicator graphic.
$('#RSSContent').removeClass('loading');
// Insert the returned HTML into the <div>.
$('#RSSContent').html(msg.d);
}
});
});
#1
11
Please see Calling Web Services from Client Script in ASP.NET AJAX:
请参阅ASP.NET AJAX中从客户端脚本调用Web服务:
This topic explains how to use to call a Web service from ECMAScript (JavaScript). To enable your application to call ASP.NET AJAX Web services by using client script, the server asynchronous communication layer automatically generates JavaScript proxy classes. A proxy class is generated for each Web service for which an
<asp:ServiceReference>
element is included under the<asp:ScriptManager>
control in the page.本主题说明如何使用ECMAScript(JavaScript)调用Web服务。为了使您的应用程序能够使用客户端脚本调用ASP.NET AJAX Web服务,服务器异步通信层会自动生成JavaScript代理类。为每个Web服务生成一个代理类,其中
元素包含在页面中的 :servicereference>控件下。 :scriptmanager>
#2
2
See Using jQuery to Consume ASP.NET JSON Web Services by Dave Ward.
请参阅Dave Ward使用jQuery来使用ASP.NET JSON Web服务。
$(document).ready(function() {
$.ajax({
type: "POST",
url: "RSSReader.asmx/GetRSSReader",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
// Hide the fake progress indicator graphic.
$('#RSSContent').removeClass('loading');
// Insert the returned HTML into the <div>.
$('#RSSContent').html(msg.d);
}
});
});