[学习日记]对SOAP请求的头添加内容的方法

方法主要是利用类的继承
继承WEB服务的代理类,然后添加新的方法,实现对SOAP请求信封的头内添加信息。

以下是生成的继类的代码,继承类的名为GetHttpHeadersProxy.vb

Imports System.Net
Imports System.Collections.Specialized

Public Class GetHttpHeadersProxy
    
Inherits getheaders.header
    
Private headerstoadd As NameValueCollection

    
Public Sub New()
        headerstoadd 
= New NameValueCollection

    
End Sub


    
Public Sub addhttpheader(ByVal headername As StringByVal headervalue As String)
        headerstoadd.Add(headername, headervalue)
    
End Sub


    
Protected Overrides Function GetWebRequest(ByVal uri As Uri) As WebRequest
        
Dim request As WebRequest
        request 
= MyBase.GetWebRequest(uri)
        request.Headers.Add(headerstoadd)
        
Return request
    
End Function

End Class

其中用绿色底高亮显示的地方为对WEB服务生成的引用类

在使用时如下方法
dim proxy as GetHttpHeadersProxy=new GetHttpHeadersProxy
proxy.AddHttpHeader(
"name","aowind")
proxy.AddHttpHeader(
"sex","man")

这样就可以在SOAP请求的头里加上所需要的值了。
posted @ 2005-03-03 11:43  Aowind  阅读(1454)  评论(1编辑  收藏  举报