JavaScript实现对WebService的引用:
使用微软提供的webservice.htc实现通过JavaScript调用WebService.
1.首先从微软网站上下载webservice.htc,我附件源代码也包含,不下载也可以
http://msdn.microsoft.com/workshop/author/webservice/webservice.htc
2.在网页BODY中添加一个DIV,实现对webservice.htc的引用

JavaScript实现对WebService的引用:<div id="service" style="BEHAVIOR:url(webservice.htc)"></div>

3.编写JavaScript,实现对WebService的引用:
JavaScript实现对WebService的引用:function window_onload() 
            }
useService 语法:
sElementID.useService(sWebServiceURL, sFriendlyName [, oUseOptions])
useService 参数:

sElementID Required. The of the element to which the behavior is attached.
sWebServiceURL Required. String specifying the URL of the Web Service, using one of the following path types. See the examples section, where several variations of this parameter are shown.
Web Service file name A Web service file, which has an .asmx file extension. This short form of the URL is sufficient, provided that the Web service is located in the same folder as the Web page using the WebService behavior. In this case, the ?WSDL query string is assumed by the behavior.
WSDL file name A Web Services Description Language (WSDL) file name. The WSDL file must have a .wsdl file extension.
Full file path Full path to a WebService (.asmx) or WSDL (.wsdl) file. A file path to a Web Service must include the ?WSDL query string. Either a local file path or a URL can be specified.
Relative path A relative path to a WebService (.asmx) or WSDL (.wsdl) file. A file path to a Web Service must include the ?WSDL query string.
sFriendlyName Required. String representing a friendly name for the Web Service URL.
oUseOptions Optional. An instance of the object.

callService语法:
iCallID = sElementID.sFriendlyName.callService( [oCallHandler], fo, oParam)
callService参数:
sElementID Required. The of the element to which the behavior is attached.
sFriendlyName Required. The friendly name for the Web Service, which is defined by calling the method.
oCallHandler Optional. Name of a script callback function that handles the results returned from this instance of the method call.
fo Required. One of the following possible values.
strFuncName A String representing the name of the remote function being called. The String must be bounded by single or double quotation marks.
objCall A object, which has the necessary properties defined to call a remote function.
oParam Required. One or more comma-delimited parameters, which are passed to the method name specified by fo.

4.建立WebService,代码如下
JavaScript实现对WebService的引用:public class Service1 : System.Web.Services.WebService
    }
5.建立测试页面
JavaScript实现对WebService的引用:<HTML>
JavaScript实现对WebService的引用:    
<HEAD>
JavaScript实现对WebService的引用:        
<title>jsWebServices</title>
JavaScript实现对WebService的引用:        
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
JavaScript实现对WebService的引用:        
<meta name="CODE_LANGUAGE" Content="C#">
JavaScript实现对WebService的引用:        
<meta name="vs_defaultClientScript" content="JavaScript">
JavaScript实现对WebService的引用:        
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
>
6.引用webservicers
7.数据库脚本
JavaScript实现对WebService的引用:if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[area]'and OBJECTPROPERTY(id, N'IsUserTable'= 1)
JavaScript实现对WebService的引用:
drop table [dbo].[area]
JavaScript实现对WebService的引用:
GO
JavaScript实现对WebService的引用:
JavaScript实现对WebService的引用:
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[province]'and OBJECTPROPERTY(id, N'IsUserTable'= 1)
JavaScript实现对WebService的引用:
drop table [dbo].[province]
JavaScript实现对WebService的引用:
GO
JavaScript实现对WebService的引用:
JavaScript实现对WebService的引用:
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[city]'and OBJECTPROPERTY(id, N'IsUserTable'= 1)
JavaScript实现对WebService的引用:
drop table [dbo].[city]
JavaScript实现对WebService的引用:
GO
JavaScript实现对WebService的引用:
JavaScript实现对WebService的引用:
CREATE TABLE [dbo].[area] (
JavaScript实现对WebService的引用:    
[id] [int] NOT NULL ,
JavaScript实现对WebService的引用:    
[areaID] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
JavaScript实现对WebService的引用:    
[area] [nvarchar] (60) COLLATE Chinese_PRC_CI_AS NULL ,
JavaScript实现对WebService的引用:    
[father] [nvarchar] (6) COLLATE Chinese_PRC_CI_AS NULL 
JavaScript实现对WebService的引用:
ON [PRIMARY]
JavaScript实现对WebService的引用:
GO
JavaScript实现对WebService的引用:
JavaScript实现对WebService的引用:
CREATE TABLE [dbo].[province] (
JavaScript实现对WebService的引用:    
[id] [int] NOT NULL ,
JavaScript实现对WebService的引用:    
[provinceID] [nvarchar] (6) COLLATE Chinese_PRC_CI_AS NULL ,
JavaScript实现对WebService的引用:    
[province] [nvarchar] (40) COLLATE Chinese_PRC_CI_AS NULL 
JavaScript实现对WebService的引用:
ON [PRIMARY]
JavaScript实现对WebService的引用:
GO
JavaScript实现对WebService的引用:
JavaScript实现对WebService的引用:
CREATE TABLE [dbo].[city] (
JavaScript实现对WebService的引用:    
[id] [int] NOT NULL ,
JavaScript实现对WebService的引用:    
[cityID] [nvarchar] (6) COLLATE Chinese_PRC_CI_AS NULL ,
JavaScript实现对WebService的引用:    
[city] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
JavaScript实现对WebService的引用:    
[father] [nvarchar] (6) COLLATE Chinese_PRC_CI_AS NULL 
JavaScript实现对WebService的引用:
ON [PRIMARY]
JavaScript实现对WebService的引用:
GO
8.下载真实数据/Files/singlepine/area.rar
9.源代码下载/Files/singlepine/jsWebServices.rar

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-01-10
  • 2022-12-23
  • 2022-12-23
  • 2022-01-12
  • 2021-08-03
  • 2022-12-23
猜你喜欢
  • 2022-02-14
  • 2022-12-23
  • 2022-02-01
  • 2022-12-23
  • 2021-05-20
  • 2022-12-23
相关资源
相似解决方案