Asynchronous Soap Invocation

Matt Paisley 116 Reputation points
2020-10-21T19:53:17.237+00:00

Hello,

I am trying to invoke a SOAP Web Service Asynchronously. I have added a handler to my code, but it is never invoked after the SOAP process has finished. Below is my code.

The Web Service is loaded and executes without issues. Upon completion, my handler is not invoked. Am I adding the Handler in the right place? Am I invoking the handler properly?

I've been struggling with this one. Any help provided will be greatly appreciated.

Regards,

Matt Paisley

Public Class DueDilligence
    Public handlerAttached As Boolean = False

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click, Button4.Click
        Dim success As Boolean, strSuccess As String
        Dim b As Button = DirectCast(sender, Button)

        Try
            Select Case b.Name
                Case "Button1"
                Case "Button4"
                    strSuccess = KycCustomerCheck()
                    If strSuccess = "Success" Then
                        txtSessionId.Text = "Processing Request"
                    Else
                        txtSessionId.Text = strSuccess
                    End If
            End Select

        Catch ex As Exception
            txtSessionId.Text = "ERROR: " & ex.Message

        End Try

    End Sub

    Private Function KycCustomerCheck() As String

        If Not handlerAttached Then
            AddHandler My.WebServices.CustomerDueDilligenceService.CustomerDueDilligenceCompleted,
                        AddressOf Me.getCDDresults
            handlerAttached = True
        End If

        Dim KYC As New CustomerDueDilligence.CustomerDueDilligenceService()
        Dim BPCredentialName As String = My.Settings.BPCredentialName
        Dim BPResourceName As String = My.Settings.BPResourceName

        Try
            KYC.Url = My.Settings.HostName & My.Settings.PortAssignment & "/ws/CustomerDueDilligence"
            KYC.Credentials = New System.Net.NetworkCredential(My.Settings.uid, My.Settings.pw)

            KYC.CustomerDueDilligenceAsync(txtFirstName.Text, txtLastName.Text,
                                           txtFirstName.Text & " " & txtLastName.Text,
                                           txtStreet.Text, txtCity.Text, txtState.Text, txtZipCode.Text)
            Return "Success"
        Catch ex As Exception
            Return "Exception - " & ex.Message
        End Try
    End Function

        Private Sub getCDDresults(ByVal sender As Object, ByVal results As CustomerDueDilligence.CustomerDueDilligenceCompletedEventArgs)

        txtSessionId.Text = "Completed"

    End Sub

End Class
Developer technologies | Windows Forms
0 comments No comments
{count} votes

Answer accepted by question author
  1. Daniel Zhang-MSFT 9,661 Reputation points
    2020-10-22T07:34:19.587+00:00

    Hi Matt Paisley,
    As this document said that "Add a method to add the event handler to the getTempCompleted event, if necessary, and to call the getTempAsync method" in step four.
    So you need to attach the event handler before calling the "CustomerDueDilligenceAsync" method.
    Best Regards,
    Daniel Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.