首先,当然是发送的SOAP头里添加信息的方法了,前面有过记录,这里就不再写了
可参见
[学习日记]对SOAP请求的头添加内容的方法
那么这次向头内添加的信息为:
dim proxy as GetHttpHeadersProxy=new GetHttpHeadersProxy
proxy.AddHttpHeader("name","aowind")
proxy.AddHttpHeader("pwd","123456")
接下来就是WEB服务方面的验证方法了。
<%@ WebService Language="vb" Class =Class="believing.Believing" %>
Imports System
Imports System.Web.Services
Imports System.IO
Imports System.Collections
Public Structure httpheaderStructure httpheader
Public name As String
Public value As String
End Structure
<System.Web.Services.WebService(Namespace :Namespace:="http://hx66.com", Description:="身份验证服务")> _
Public Class BelievingClass Believing
Inherits System.Web.Services.WebService
<WebMethod(Description:="<font color=green>身份验证方法</font>")> _
Public Function lianzheng()Function lianzheng() As String
dim name,pwd as string
name=Context.Request.Headers("name")
pwd=Context.Request.Headers("pwd")
If (用户表中存在name) And (用户表中存在pwd) Then
Try
.
Catch ex As Exception
Return ex.ToString
End Try
Return "OK!"
Else
Return "用户名或都密码有误,请求不于处理"
End If
End Function
可以看到
name=Context.Request.Headers("name")
pwd=Context.Request.Headers("pwd")
这两句就是从SOAP头中取出数据
也可以用索引方式来取得
Context.Request.Headers(0).value