WCF AsyncPattern-异步调用链-Silverlight [英] WCF AsyncPattern - asynchronous call chain - Silverlight

查看:64
本文介绍了WCF AsyncPattern-异步调用链-Silverlight的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在WCF服务上实现异步模式,但不知道如何.

在第一个合同中返回身份时,结果将提供给第二个服务.

如果不是,则来自第二项服务的结果将转到第三项.
返回结果到UI

第三项服务的结果为真
返回结果到UI.

如果该服务未返回"1",我将创建另一个保存的服务.

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.

<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

推荐答案

您发布的代码与问题无关.

在客户端,如果您在创建服务引用时生成异步调用,则合同中的每个操作都会有一个在完成时被调用的事件.订阅这些事件.调用第一个操作....当其完成的事件处理程序被调用时,调用下一个异步操作并等待其完成的事件,依此类推.那是链式的.
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.


这篇关于WCF AsyncPattern-异步调用链-Silverlight的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆