[Learning diary] how to add content to the SOAP request header

Source: Internet
Author: User

The method mainly utilizes class inheritance.
Inherit the WEB Service proxy class and add a new method to add information to the header of the SOAP request envelope.

The following is the generated code for the inherited class: GetHttpHeadersProxy. vb

Imports System. Net
Imports System. Collections. Specialized

Public Class GetHttpHeadersProxyClass GetHttpHeadersProxy
Inherits getheaders. header
Private headerstoadd As NameValueCollection

Public Sub New ()
Headerstoadd = New NameValueCollection

End Sub

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

Protected Overrides Function GetWebRequest () 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

The highlighted green background is the reference class generated for the WEB service.

The following method is used for usage: dim proxy as GetHttpHeadersProxy = new GetHttpHeadersProxy
Proxy. AddHttpHeader ("name", "aowind ")
Proxy. AddHttpHeader ("sex", "man ")

In this way, you can add the required value to the header of the SOAP request.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.