zoukankan
html css js c++ java
webservice 实现动态刷新
FeaturedService.asmx
using
System;
using
System.Collections;
using
System.ComponentModel;
using
System.Data;
using
System.Diagnostics;
using
System.Web;
using
System.Web.Services;
using
System.Data .SqlClient ;
namespace
WebService
{
/**/
///
<summary>
///
FeaturedService 的摘要说明。
///
</summary>
public
class
FeaturedService : System.Web.Services.WebService
{
public
FeaturedService()
{
//
CODEGEN: 该调用是 ASP.NET Web 服务设计器所必需的
InitializeComponent();
}
组件设计器生成的代码
#region
组件设计器生成的代码
//
Web 服务设计器所必需的
private
IContainer components
=
null
;
/**/
///
<summary>
///
设计器支持所需的方法 - 不要使用代码编辑器修改
///
此方法的内容。
///
</summary>
private
void
InitializeComponent()
{
}
/**/
///
<summary>
///
清理所有正在使用的资源。
///
</summary>
protected
override
void
Dispose(
bool
disposing )
{
if
(disposing
&&
components
!=
null
)
{
components.Dispose();
}
base
.Dispose(disposing);
}
#endregion
//
WEB 服务示例
//
HelloWorld() 示例服务返回字符串 Hello World
//
若要生成,请取消注释下列行,然后保存并生成项目
//
若要测试此 Web 服务,请按 F5 键
[WebMethod]
public
string
GetFeatured()
{
string
strSelect;
SqlConnection conPubs;
SqlDataAdapter dadPubs;
DataSet dstTitles;
DataRow drowTitle;
Random objRanNum;
int
intRanNum;
strSelect
=
"
SELECT Title, isNull( Notes, '' ) Notes From Titles
"
;
conPubs
=
new
SqlConnection(
"
server=(local);database=pubs;uid=sa;pwd=
"
);
dadPubs
=
new
SqlDataAdapter( strSelect, conPubs );
dstTitles
=
new
DataSet();
dadPubs.Fill( dstTitles,
"
Titles
"
);
objRanNum
=
new
Random();
intRanNum
=
objRanNum.Next(
0
, dstTitles.Tables[
"
Titles
"
].Rows.Count );
drowTitle
=
dstTitles.Tables[
"
Titles
"
].Rows[intRanNum];
return
drowTitle[
"
Title
"
]
+
"
-
"
+
drowTitle[
"
Notes
"
];
}
}
}
调用页面
<%
@ Page language
=
"
c#
"
Codebehind
=
"
WebForm1.aspx.cs
"
AutoEventWireup
=
"
false
"
Inherits
=
"
WebService.WebForm1
"
%>
<!
DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
>
<
HTML
>
<
HEAD
>
<
title
>
WebForm1
</
title
>
<
meta
name
="GENERATOR"
Content
="Microsoft Visual Studio .NET 7.1"
>
<
meta
name
="CODE_LANGUAGE"
Content
="C#"
>
<
meta
name
="vs_defaultClientScript"
content
="JavaScript"
>
<
meta
name
="vs_targetSchema"
content
="http://schemas.microsoft.com/intellisense/ie5"
>
<
script
>
var
intCallID
=
0
;
function
Init()
{
GetNewFeatured();
setInterval(
"
GetNewFeatured()
"
,
5000
)
}
function
GetNewFeatured()
{
service.useService(
"
FeaturedService.asmx?WSDL
"
,
"
FeaturedService
"
);
intCallID
=
service.FeaturedService.callService(
"
GetFeatured
"
);
}
function
Service_Result()
{
if
(event.result.error)
{
divFeatured.innerText
=
event.result.errorDetail.string;
}
else
{
divFeatured.innerText
=
event.result.value;
}
}
</
script
>
</
HEAD
>
<
body
MS_POSITIONING
="GridLayout"
onload
="Init()"
>
<
form
id
="Form1"
method
="post"
runat
="server"
>
<
table
width
="600"
>
<
tr
>
<
td
valign
="top"
>
<
h2
>
Welcome to this Web Site!
</
h2
>
Browse this Web site to get great deals on the latest books!
</
td
>
<
td
>
<
div
id
="service"
style
="behavior:url(webservice.htc)"
onresult
="Service_Result()"
></
div
>
<
div
id
="divFeatured"
style
="BORDER-RIGHT:darkgreen 1px solid;PADDING-RIGHT:10px;BORDER-TOP:darkgreen 1px solid;PADDING-LEFT:10px;PADDING-BOTTOM:10px;BORDER-LEFT:darkgreen 1px solid;WIDTH:200px;PADDING-TOP:10px;BORDER-BOTTOM:darkgreen 1px solid"
>
</
div
>
</
td
>
</
tr
>
</
table
>
</
form
>
</
body
>
</
HTML
>
实现效果
还有就是要注意那个webservice.htc文件.....
一定要放在程序目录下...
查看全文
相关阅读:
Sublime Text 3 支持的热门插件推荐
Sublime text 2/3 中 Package Control 的安装与使用方法
UML类图中箭头和线条的含义和用法
this guy gonna be a daddy
PHP设计模式之:单例模式
PHP FTP操作类( 上传、拷贝、移动、删除文件/创建目录 )
php memcache 基础操作
获取IP地址方法
短信发送
使用Shell脚本对Linux系统和进程资源进行监控
原文地址:https://www.cnblogs.com/gwazy/p/152205.html
最新文章
【读英文文档】Whetting Your Appetite(刺激你的食欲)
python 环境搭建及pycharm的使用
stm32之通信
stm32之存储系统
SRAM SROM DRAM DROM DDR NAND FLASH EMMC的区别
stm32之复位与待机唤醒
stm32之时钟控制
stm32之开发入门
stm32之入门知识
嵌入式入门知识
热门文章
在Windows环境中学习Linux
Win10下Anaconda中安装Tensorflow
提升自己,时间管理方法
一个软件开发工程师的7年工作经验总结
GIT:如何管理本机的多个ssh密钥(多个远程仓库账号)
基于yaf框架和uploadify插件,做的一个导入excel文件,查看并保存数据的功能
GIT常用命令
yaf的简单入门
成就PHP高手的五个必由之路
PHP 多图片上传实例demo
Copyright © 2011-2022 走看看