Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 764
  • Last Modified:

Creating a Soap Header

Hi i want to add a soap header in the function give below.Could anyone please help me how to add this header


Public Function ProcessRequest(ByVal paymentRequest As RebillPayment, ByVal Proxy As String) As Boolean
 
        
        
        Dim request As HttpWebRequest = CType(HttpWebRequest.Create(_uri), HttpWebRequest)
        If Proxy IsNot Nothing Then
            request.Proxy = New WebProxy(Proxy, True)
        End If
        ' if SOAPAction header is required, add it here... 
        request.Headers.Add("SOAPAction", """""")
        request.Method = "POST"
        request.Timeout = _timeout
        request.ContentType = "application/x-www-form-urlencoded"
        request.KeepAlive = False
        Dim requestBytes As Byte() = System.Text.Encoding.ASCII.GetBytes(paymentRequest.ToXML)
        request.ContentLength = requestBytes.Length
 
        Try
            Dim requestStream As Stream = request.GetRequestStream
            requestStream.Write(requestBytes, 0, requestBytes.Length)
            requestStream.Close()
        Catch
            Return False
        End Try
 
        Dim response As HttpWebResponse = Nothing
 
        Try
            response = CType(request.GetResponse, HttpWebResponse)
        Catch wex As WebException
            If response Is Nothing Then
                Return False
            End If
            response = CType(wex.Response, HttpWebResponse)
            Dim sr As StreamReader = Nothing
            sr = New StreamReader(response.GetResponseStream, System.Text.Encoding.ASCII)
            Dim _wexBody As String = sr.ReadToEnd
            sr.Close()
            Return False
        Catch
            Return False
        End Try
 
        If response.StatusCode = HttpStatusCode.OK Then
            Dim sr As StreamReader = Nothing
            sr = New StreamReader(response.GetResponseStream, System.Text.Encoding.ASCII)
            Dim _serverXml As String = sr.ReadToEnd
            sr.Close()
            Try
                _response = New RebillResponse(_serverXml)
                Return True
            Catch
                Return False
            End Try
        Else
            Return False
        End If
    End Function

Open in new window

0
lakshmidurga
Asked:
lakshmidurga
1 Solution
 
vjc2003Commented:
The SOAP request headers depends on which is the web service url/method you are planning to invoke:

In general these are the request params required:
request.Headers.Add("SOAPAction", soapAction)  
request.Method = "POST"
request.Timeout = _timeout
request.ContentType = "text/xml; charset=utf-8"  [assuming you are going to send a xml as post data]
request.ContentLength = requestBytes.Length

You can find out the soapAction for a method by browsing the webservice url/method.


0
 
lakshmidurgaAuthor Commented:
close this question
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now