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文件.....
一定要放在程序目录下...
查看全文
相关阅读:
C++ 扩展 Op
Python 扩展 Op
VS Code 调试 OneFlow
运行时数据获取
OFRecord 图片文件制数据集
OFRecord 数据集加载
OFRecord 数据格式
OneFlow 并行特色
Consistent 与 Mirrored 视角
作业函数的定义与调用
原文地址:https://www.cnblogs.com/gwazy/p/152205.html
最新文章
如何快速准备高质量的AI数据?
20年研发安全积累,5大研发安全能力让软件“天生安全”
CloudIDE:为开发者写代码开启“加速”模式
云原生开发者须具备的1+N技能,开启第二曲线
Codeforces Round #665 (Div. 2) A
19级暑假第七场训练赛
A*(A star)搜索总结
Codeforces Round #629 (Div. 3) & 19级暑假第六场训练赛
线性代数(1):矩阵以及运用
__builtin_popcount() 函数
热门文章
【洛谷日报#26】GCC自带位运算系列函数
Swoole跟thinkphp5结合开发WebSocket在线聊天通讯系统
PHP 将数据从 Laravel 传送到 vue 的四种方式
【实战】如何通过html+css+mysql+php来快速的制作动态网页(以制作一个博客网站为列)
Java实现 LeetCode 781 森林中的兔子(分析题)
540. Single Element in a Sorted Array
386. Lexicographical Numbers
1437. Check If All 1's Are at Least Length K Places Away
733. Flood Fill
392. Is Subsequence
Copyright © 2011-2022 走看看