Calling Web Service from Client-Side JavaScript
来源:互联网 发布:淘宝大衣比较好的店铺 编辑:程序博客网 时间:2024/05/16 14:07
This tip basically helps the developer to call the web service from client-side JavaScript.
è First, create a web service project using and give the namespace and the class name as “consumeDnTWebSvc” and write a method called “HelloWorld” as follows:
[WebMethod]
public string HelloWorld()
{
return "Test is Successfull...!!!";
}
à This is basically a very simple method.
è Second, create a web application. Once created the project, download webservice.htc file from this link http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/samples/internet/behaviors/library/webservice/default.asp
Note: The program will not work without this htc file.
In the .aspx file, copy the following code under the <HEAD> tag:
<SCRIPT language="JavaScript">
function initWebHTC()
{
//init and create short-cut name for web service
dNtWbSvc.useService("http://YourAddress/WebServiceProjectName/XXX.asmx?WSDL","dNtSvc");
var iCallID;
if (dNtWbSvc.dNtSvc)
{
//document.getElementById("lblDateTime").innerHTML="Loading..."
iCallID= dNtWbSvc.dNtSvc.callService(gtDnTRslt,"HelloWorld");
}
}
function gtDnTRslt(result)
{
//if an error then get error details
if(result.error)
{
//Pull error info from event.result.errorDetail properties
var xfaultcode = result.errorDetail.code;
var xfaultstring = result.errorDetail.string;
var xfaultsoap = result.errorDetail.raw;
// Add code to handle specific error codes here
//document.getElementById("lblDateTime").innerHTML="Error: " + xfaultcode + " ; " + xfaultstring + " ; " + xfaultsoap;
alert("Error: " + xfaultcode + " ; " + xfaultstring + " ; " + xfaultsoap);
}
else
{
//document.getElementById("lblDateTime").innerHTML=result.value;
alert(result.value);
//clear any selection
var sRng;
sRng = document.selection.createRange();
sRng.execCommand("unselect");
}
}
</SCRIPT>
Add the following code under <BODY> tag:
<body MS_POSITIONING="GridLayout" ondblclick="initWebHTC();">
<DIV id="dNtWbSvc" style="BEHAVIOR: url(http://YourAddress/SecondProjectName/webservice.htc)"></DIV>
<form id="frmWebSvcDateTime" method="post" runat="server">
<asp:Label backcolor="#99eedd" id="lblDateTime" runat="server" Width="581px" Height="36px">Sample Text Here</asp:Label>
</form>
- Calling Web Service from Client-Side JavaScript
- Embed client-side JavaScript in an ASP.NET 1.1 web page from server side code
- Calling a Web API From a .NET Client (C#)
- Calling a Web API From a .NET Client
- 转: Calling a SAP Web Service from VS.Net
- Calling a web-service from a Unity3D scene
- Calling Wicket from Javascript,
- Calling Web Services From Html Pages using Javascript
- Call Web Service from a VC++ 6.0 Client
- Calling web service using AJAX
- Call JavaScript from server side
- 三种 Failover 之 Client-Side Connect time Failover、Client-Side TAF、Service-Side TAF
- File Handling at Client Side Using Javascript
- Web Service Tip: JSPs Calling Web Services
- Web Service & Client
- xfire-web service -client
- 建立web service client
- Calling Flex / Actionscript functions from Javascript
- HowTO: Setup Alerts for Portal Home Page "Listings"
- WebPart从bin改部署到GAC时资源文件丢失之谜(downmoon)
- 上班第三天---雨下得很大
- 佛祖说出的爱情箴言
- PHP中 ADOdb 类库介绍
- Calling Web Service from Client-Side JavaScript
- 上班第二天——上轨
- Adodb 官方介绍
- 《CSDN社区电子杂志——移动开发杂志》2005年7月第3期,总第3期发布!!!
- VC自绘按钮的实现(NO MFC)
- 如今博客中国迷失于门户旋涡,正遭受个人门户带来的巨大压力
- DATAGRID更新事件时,必须加上!ispostback,如果不加的话。得不到textbox的值
- CVS安装和使用心得
- 【新闻】我国将取代印度成为全球最大的技术外包市场