博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
WebService编程笔记(一)
阅读量:5998 次
发布时间:2019-06-20

本文共 8548 字,大约阅读时间需要 28 分钟。

一、将WebService方法与AJAX联系起来:
0. Web.Config文件中要加入一些东东(具体再分析)
ExpandedBlockStart.gif
代码
<?
xml version
=
"
1.0
"
?>
<
configuration
>
    
<
configSections
>
        
<
sectionGroup name
=
"
system.web.extensions
"
 type
=
"
System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35
"
>
            
<
sectionGroup name
=
"
scripting
"
 type
=
"
System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35
"
>
                
<
section name
=
"
scriptResourceHandler
"
 type
=
"
System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35
"
 requirePermission
=
"
false
"
 allowDefinition
=
"
MachineToApplication
"
/>
                
<
sectionGroup name
=
"
webServices
"
 type
=
"
System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35
"
>
                    
<
section name
=
"
jsonSerialization
"
 type
=
"
System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35
"
 requirePermission
=
"
false
"
 allowDefinition
=
"
Everywhere
"
/>
                    
<
section name
=
"
profileService
"
 type
=
"
System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35
"
 requirePermission
=
"
false
"
 allowDefinition
=
"
MachineToApplication
"
/>
                    
<
section name
=
"
authenticationService
"
 type
=
"
System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35
"
 requirePermission
=
"
false
"
 allowDefinition
=
"
MachineToApplication
"
/>
                    
<
section name
=
"
roleService
"
 type
=
"
System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35
"
 requirePermission
=
"
false
"
 allowDefinition
=
"
MachineToApplication
"
/>
                
</
sectionGroup
>
            
</
sectionGroup
>
        
</
sectionGroup
>
    
</
configSections
>
    
<
appSettings
/>
    
<
connectionStrings
>
        
<
add name
=
"
connstr
"
 connectionString
=
"
Data Source=medal;Initial Catalog=EmailSystem;Integrated Security=True
"
/>
    
</
connectionStrings
>
    
<!--
配置dataTable序列化开始
-->
    
<
system.web.extensions
>
        
<
scripting
>
            
<
webServices
>
                
<
jsonSerialization
>
                    
<
converters
>
                        
<
add name
=
"
DataSetConverter
"
 type
=
"
Microsoft.Web.Preview.Script.Serialization.Converters.DataSetConverter,Microsoft.Web.Preview, Version=1.0.61025.0, Culture=neutral,PublicKeyToken=31bf3856ad364e35
"
/>
                        
<
add name
=
"
DataRowConverter
"
 type
=
"
Microsoft.Web.Preview.Script.Serialization.Converters.DataRowConverter,Microsoft.Web.Preview, Version=1.0.61025.0, Culture=neutral,PublicKeyToken=31bf3856ad364e35
"
/>
                        
<
add name
=
"
DataTableConverter
"
 type
=
"
Microsoft.Web.Preview.Script.Serialization.Converters.DataTableConverter,Microsoft.Web.Preview, Version=1.0.61025.0, Culture=neutral,PublicKeyToken=31bf3856ad364e35
"
/>
                    
</
converters
>
                
</
jsonSerialization
>
            
</
webServices
>
        
</
scripting
>
    
</
system.web.extensions
>
    
<!--
配置dataTable序列化结束
-->
    
<
system.web
>
        
<!--
 
            设置 compilation debug
=
"
true
"
 可将调试符号插入
            已编译的页面中。但由于这会 
            影响性能,因此只在开发过程中将此值 
            设置为 
true
        
-->
        
<
compilation debug
=
"
true
"
>
            
<
assemblies
>
                
<
add assembly
=
"
System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089
"
/>
                
<
add assembly
=
"
System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089
"
/>
                
<
add assembly
=
"
System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35
"
/>
                
<
add assembly
=
"
System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089
"
/>
            
</
assemblies
>
        
</
compilation
>
        
<!--
            通过 
<
authentication
>
 节可以配置 ASP.NET 用来 
            识别进入用户的
            安全身份验证模式。 
        
-->
        
<
authentication mode
=
"
Windows
"
/>
        
<!--
            如果在执行请求的过程中出现未处理的错误,
            则通过 
<
customErrors
>
 节可以配置相应的处理步骤。具体说来,
            开发人员通过该节可以配置
            要显示的 html 错误页
            以代替错误堆栈跟踪。
        
<
customErrors mode
=
"
RemoteOnly
"
 defaultRedirect
=
"
GenericErrorPage.htm
"
>
            
<
error statusCode
=
"
403
"
 redirect
=
"
NoAccess.htm
"
 
/>
            
<
error statusCode
=
"
404
"
 redirect
=
"
FileNotFound.htm
"
 
/>
        
</
customErrors
>
        
-->
        
<
pages
>
            
<
controls
>
                
<
add tagPrefix
=
"
asp
"
 
namespace
=
"
System.Web.UI
"
 assembly
=
"
System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35
"
/>
                
<
add tagPrefix
=
"
asp
"
 
namespace
=
"
System.Web.UI.WebControls
"
 assembly
=
"
System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35
"
/>
            
</
controls
>
        
</
pages
>
        
<
httpHandlers
>
            
<
remove verb
=
"
*
"
 path
=
"
*.asmx
"
/>
            
<
add verb
=
"
*
"
 path
=
"
*.asmx
"
 validate
=
"
false
"
 type
=
"
System.Web.Script.Services.ScriptHandlerFactory
"
/>
            
<
add verb
=
"
GET,HEAD
"
 path
=
"
ScriptResource.axd
"
 type
=
"
System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
"
 validate
=
"
false
"
/>
        
</
httpHandlers
>
        
<
httpModules
>
            
<
add name
=
"
ScriptModule
"
 type
=
"
System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35
"
/>
        
</
httpModules
>
    
</
system.web
>
    
<
system.codedom
>
        
<
compilers
>
            
<
compiler language
=
"
c#;cs;csharp
"
 extension
=
"
.cs
"
 warningLevel
=
"
4
"
 type
=
"
Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
"
>
                
<
providerOption name
=
"
CompilerVersion
"
 value
=
"
v3.5
"
/>
                
<
providerOption name
=
"
WarnAsError
"
 value
=
"
false
"
/>
            
</
compiler
>
        
</
compilers
>
    
</
system.codedom
>
    
<!--
 
        在 Internet 信息服务 
7.0
 下运行 ASP.NET AJAX 需要 system.webServer
        节。对早期版本的 IIS 来说则不需要此节。
    
-->
    
<
system.webServer
>
        
<
validation validateIntegratedModeConfiguration
=
"
false
"
/>
        
<
modules
>
            
<
remove name
=
"
ScriptModule
"
/>
            
<
add name
=
"
ScriptModule
"
 preCondition
=
"
managedHandler
"
 type
=
"
System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35
"
/>
        
</
modules
>
        
<
handlers
>
            
<
remove name
=
"
WebServiceHandlerFactory-Integrated
"
/>
            
<
remove name
=
"
ScriptHandlerFactory
"
/>
            
<
remove name
=
"
ScriptHandlerFactoryAppServices
"
/>
            
<
remove name
=
"
ScriptResource
"
/>
            
<
add name
=
"
ScriptHandlerFactory
"
 verb
=
"
*
"
 path
=
"
*.asmx
"
 preCondition
=
"
integratedMode
"
 type
=
"
System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35
"
/>
            
<
add name
=
"
ScriptHandlerFactoryAppServices
"
 verb
=
"
*
"
 path
=
"
*_AppService.axd
"
 preCondition
=
"
integratedMode
"
 type
=
"
System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35
"
/>
            
<
add name
=
"
ScriptResource
"
 preCondition
=
"
integratedMode
"
 verb
=
"
GET,HEAD
"
 path
=
"
ScriptResource.axd
"
 type
=
"
System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35
"
/>
        
</
handlers
>
    
</
system.webServer
>
    
<
runtime
>
        
<
assemblyBinding xmlns
=
"
urn:schemas-microsoft-com:asm.v1
"
>
            
<
dependentAssembly
>
                
<
assemblyIdentity name
=
"
System.Web.Extensions
"
 publicKeyToken
=
"
31bf3856ad364e35
"
/>
                
<
bindingRedirect oldVersion
=
"
1.0.0.0-1.1.0.0
"
 newVersion
=
"
3.5.0.0
"
/>
            
</
dependentAssembly
>
            
<
dependentAssembly
>
                
<
assemblyIdentity name
=
"
System.Web.Extensions.Design
"
 publicKeyToken
=
"
31bf3856ad364e35
"
/>
                
<
bindingRedirect oldVersion
=
"
1.0.0.0-1.1.0.0
"
 newVersion
=
"
3.5.0.0
"
/>
            
</
dependentAssembly
>
        
</
assemblyBinding
>
    
</
runtime
>
</
configuration
>
1. 定义一个webservice页面.asmx
[System.Web.Script.Services.ScriptService] 取消屏蔽
2. 其中的方法应该为public且增加属性[WebMethod]  <form id="form1" runat="server">
 
3. 在Aspx页面中,加入AJAX控件如下,并在ServiceReference Path中链接web service页面,如下:
ExpandedBlockStart.gif
代码
    
<
form 
id
="form1"
 runat
="server"
>
    
<
div
>
    
<
asp:ScriptManager 
ID
="ScriptManager1"
 runat
="server"
>
    
<
Services
>
    
<
asp:ServiceReference 
Path
="WebServiceData.asmx"
 
/>
    
</
Services
>
    
</
asp:ScriptManager
>
    
</
div
>
    
</
form
>

4. 在JS代码中使用WebServiceTableSort.WebServiceData.GetDataList(OnSuccessed),GetDataList()函数是在web service中使用[WebMethod]定义的服务器方法,其中OnSuccessed为成功后所调用的方法,且带参数为GetDataList()函数的返回值

 

二、AJAX类:

1、在JS代码中直接使用服务器端的控件:
var builder = new Sys.StringBuilder("");
具体:http://www.asp.net/AJAX/documentation/live/ClientReference/Sys/StringBuilderClass/default.aspx

转载地址:http://jfzmx.baihongyu.com/

你可能感兴趣的文章
每天记录一点:NetCore获得配置文件 appsettings.json vue-router页面传值及接收值 详解webpack + vue + node 打造单页面(入门篇) 30...
查看>>
点击按钮,进入全屏与退出全屏切换
查看>>
在mysql命令行下执行sql文件
查看>>
【win7 + win server 2008】设置定时任务,设置.bat 文件去执行php脚本 == 用来配合爬虫程序简直不要太爽...
查看>>
php资源类型变量
查看>>
WebStorm(Amaze开发工具)--JavaScript 开发工具
查看>>
SpringBoot消失的Web.xml
查看>>
Map容器线程安全问题
查看>>
解决Vue用Nginx做web服务器报错favicon.ico 404 (Not Found)的问题
查看>>
dancing links
查看>>
工作总结 mvc 调页面传参数 参数值会一直保存 在这个页面上的
查看>>
Python爬虫之三种网页抓取方法性能比较
查看>>
sqlachemy 查询当日数据,
查看>>
C#操作Sqlite快速入门及相关工具收集
查看>>
关于调用Feign client超时得不到结果的问题
查看>>
FaceBook登陆API -- Login with API calls
查看>>
UWP 查找模板中的控件
查看>>
Mysql错误: ERROR 1205: Lock wait timeout exceeded解决办法(MySQL锁表、事物锁表的处理方法)...
查看>>
WPF- 模拟触发Touch Events
查看>>
Windows中查看PowerShell版本和virbox版本,vagrant 版本
查看>>