Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I would like to implement the async pattern on my WCF service and don't know how.

When the identity is returned in the first contract, the results feed the second service.

The results that come from the second service if not true will go to third
return result to UI

Results from the third service is true
return result to UI.

If thrid service not return '1' I will create another services that saves.
VB
<ServiceContract(Namespace:="")>
<AspNetCompatibilityRequirements(RequirementsMode:=AspNetCompatibilityRequirementsMode.Allowed)>
Public Class MyService

    <OperationContract()>
    Public Function GetNums() As String
        
            Return HttpContext.Current.User.Identity.Name.ToString()
        
    End Function
    <OperationContract()>
    Public Function GetMoreUserData(ByVal Uid As String) As List(Of Entity)
        Dim list As List(Of Entity) = New List(Of Entity)()
        Using conn As SqlConnection = New SqlConnection("MyConnection/Database")
            conn.Open()
            Using dcmd As SqlCommand = New SqlCommand("StoredProcedure", conn)
                Dim prms As New SqlParameter("@Uid", SqlDbType.VarChar, 70)
                prms.Value = Uid & "%"
                dcmd.Parameters.Add(prms)
                dcmd.CommandType = CommandType.StoredProcedure
                Using reader As SqlDataReader = dcmd.ExecuteReader()
                    While reader.Read()
                        list.Add(New Entity() With { _
                                 .NUM = reader("NUM").ToString() _
                                })
                    End While
                End Using
                conn.Close()
            End Using
            Return list
        End Using
    End Function

    <OperationContract()>
    Public Function GetAuthorizeDivision(ByVal NUM As String) As List(Of Entity)
        Dim list As List(Of Entity) = New List(Of Entity)()
        Using conn As SqlConnection = New SqlConnection("MyDatabaseConnection")
            conn.Open()
            Using dcmd As SqlCommand = New SqlCommand("StoredProcedure", conn)
                Dim prms As New SqlParameter("@NUM", SqlDbType.VarChar, 9)
                prms.Value = NUM & "%"
                dcmd.Parameters.Add(prms)
                dcmd.CommandType = CommandType.StoredProcedure
                Using reader As SqlDataReader = dcmd.ExecuteReader()
                    While reader.Read()
                        list.Add(New Entity() With { _
                                 .YESGO = reader("YESGO").ToString() _
                                 })
                    End While
                End Using
                conn.Close()
            End Using
            Return list
        End Using
    End Function

    <OperationContract()>
    Public Function GetAuthorizedAppU(ByVal EAPPNUM As String) As List(Of Entity)
        Dim list As List(Of Entity) = New List(Of Entity)()
        Using conn As SqlConnection = New SqlConnection("MyDatabase/Connetion")
            conn.Open()
            Using dcmd As SqlCommand = New SqlCommand("StoredProcedure", conn)
                Dim prms As New SqlParameter("@EAPPNUM", SqlDbType.VarChar, 15)
                prms.Value = EAPPNUM & "%"
                dcmd.Parameters.Add(prms)
                dcmd.CommandType = CommandType.StoredProcedure

                Using reader As SqlDataReader = dcmd.ExecuteReader
                    While reader.Read()
                        list.Add(New Entity() With { _
                                 .Column1 = reader("Column1").ToString _
                                 })
                    End While
                    conn.Close()
                End Using
                Return list
            End Using
        End Using
    End Function
Posted
Updated 31-May-11 7:46am
v2

1 solution

The code you posted has nothing to do with the question.

On the client side, if you generate asynchronous calls when you create a service reference, each operation in the contract will have an event that's called on completion. Subscribe to these events. Call the first operation....when its completed event handler is called, call the next async operation and wait for its completed event, and so on. That's chained.
 
Share this answer
 
Comments
technette 31-May-11 13:47pm    
I was originally trying to handle this in the completed event but the completed event will not call the next service... don't know what I'm doing wrong..

Private Sub GetAuthorizeUserCompleted(ByVal sender As Object, ByVal e As WinAuthsv.GetAuthorizeUserCompletedEventArgs)
Dim txtActive As New ListBox
txtActive.ItemsSource = e.Result

If txtActive.ItemsSource = "Active" Then
Return
Else

AddHandler AuthServ.GetAuthorizedOtherTypeCompleted, AddressOf GetAuthorizedOtherTypeCompleted
AuthServ.GetAuthorizedOtherTypeAsync(TEXTIDnum.ItemsSource)

End If

End Sub
Mark Salsbery 31-May-11 13:51pm    
What do you mean "will not call the next service"? Is there an exception thrown?
technette 31-May-11 14:14pm    
No exception thrown...

Am I calling the next service correctly? Maybe I need to organize the order of operation better. I have three services that depend of the execution of the previous.

When I'm adding these services to Main Page or Home Page.... which is better?

Should I call the service before the navigation code or after?
Mark Salsbery 31-May-11 15:10pm    
I don't know VB but it looks right :) Have you put a breakpoint in the server operation code to see if the call is getting there?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900