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

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

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

None.gif Imports  System.Net
None.gif
Imports  System.Collections.Specialized
None.gif
ExpandedBlockStart.gifContractedBlock.gif
Public   Class GetHttpHeadersProxy Class GetHttpHeadersProxy
InBlock.gif    
Inherits getheaders.header
InBlock.gif    
Private headerstoadd As NameValueCollection
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Public Sub New()Sub New()
InBlock.gif        headerstoadd 
= New NameValueCollection
InBlock.gif
ExpandedSubBlockEnd.gif    
End Sub

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Public Sub addhttpheader()Sub addhttpheader(ByVal headername As StringByVal headervalue As String)
InBlock.gif        headerstoadd.Add(headername, headervalue)
ExpandedSubBlockEnd.gif    
End Sub

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

ExpandedBlockEnd.gif
End Class

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

在使用时如下方法
None.gif dim  proxy  as  GetHttpHeadersProxy = new  GetHttpHeadersProxy
None.gifproxy.AddHttpHeader(
" name " , " aowind " )
None.gifproxy.AddHttpHeader(
" sex " , " man " )
None.gifdot.gif
None.gif
这样就可以在SOAP请求的头里加上所需要的值了。

转载于:https://www.cnblogs.com/aowind/archive/2005/03/03/111970.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值