[学习日记]对SOAP头内添加信息的验证,可实现对请求WEB服务进行身份验证。

博客介绍了在SOAP请求头添加信息的方法,如添加'name'和'pwd'。还阐述了WEB服务的验证方法,通过从SOAP头中取出数据,判断用户表中是否存在相应的'name'和'pwd',以确定请求是否处理。
首先,当然是发送的SOAP头里添加信息的方法了,前面有过记录,这里就不再写了
可参见
[学习日记]对SOAP请求的头添加内容的方法
 
那么这次向头内添加的信息为:
None.gif dim  proxy  as  GetHttpHeadersProxy = new  GetHttpHeadersProxy
None.gifproxy.AddHttpHeader(
" name " , " aowind " )
None.gifproxy.AddHttpHeader(
" pwd " , " 123456 " )
None.gif

接下来就是WEB服务方面的验证方法了。
ExpandedBlockStart.gif ContractedBlock.gif < %@ WebService Language = " vb "    Class = Class="believing.Believing" %>
InBlock.gif
InBlock.gif
Imports System
InBlock.gif
Imports System.Web.Services
InBlock.gif
Imports System.IO
InBlock.gif
Imports System.Collections
InBlock.gif
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif
Public Structure httpheaderStructure httpheader
InBlock.gif    
Public name As String
InBlock.gif    
Public value As String
ExpandedSubBlockEnd.gif
End Structure

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif
<System.Web.Services.WebService(Namespace :Namespace:="http://hx66.com", Description:="身份验证服务")> _
ExpandedSubBlockStart.gifContractedSubBlock.gif
Public Class BelievingClass Believing
InBlock.gif    
Inherits System.Web.Services.WebService
InBlock.gif
InBlock.gif        
<WebMethod(Description:="<font color=green>身份验证方法</font>")> _
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Public Function lianzheng()Function lianzheng() As String
InBlock.gif
dim name,pwd as string
InBlock.gifname
=Context.Request.Headers("name"
InBlock.gifpwd
=Context.Request.Headers("pwd"
InBlock.gif        
If  (用户表中存在name) And (用户表中存在pwd)  Then
InBlock.gif           Try
InBlock.gifdot.gifdot.gifdot.gif.            
InBlock.gif            
Catch ex As Exception
InBlock.gif                
Return ex.ToString
InBlock.gif            
End Try
InBlock.gif            
Return "OK!" 
InBlock.gif        
Else
InBlock.gif            
Return "用户名或都密码有误,请求不于处理"
InBlock.gif
        End If
ExpandedSubBlockEnd.gif     
End Function

可以看到
name = Context.Request.Headers( " name "
pwd
= Context.Request.Headers( " pwd "
这两句就是从SOAP头中取出数据
也可以用索引方式来取得
Context.Request.Headers(0).value
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值