Salve ragazzi...
Ho provato a scrivere un semplice progetto in Workflow Foundation con VB.NET ma ho trovato dei problemi.
con CallExternalMethodActivity tutto ok, ma se richiamo una HandleExternalEventActivity, al Workflow non arriva l'evento e ciò comporta che tutto il flusso si blocca chissà per quale mio errore.
Credo che non sia esatta la dichiarazione del "Raise Event ToWorkflowEvent" contenuta nella classe del servizio.
Se eseguo il Debug dell'applicazione, cliccando sul tasto che effettua la chiamata al metodo del servizio al cui interno c'è il Raise Dell'evento, una volta passato per il Raise non succede nulla.
In qualche modo il Workflow sembra che non intercetti l'evento lanciato dalla classe servizio.
Avete qualche idea?
vi inserisco il codice qua sotto...
Namespace Common che contiene Interfaccia, Servizio e Argomenti
Namespace Common
<Serializable()> Public Class MyEventArgs
Inherits ExternalDataEventArgs
Private _Message As String
Public Property Message()
Get
Return _Message
End Get
Set(ByVal value)
_Message = value
End Set
End Property
Public Sub New(ByVal InstanceID As Guid, _
ByVal Message As String)
MyBase.New(InstanceID)
_Message = Message
End Sub
End Class
<ExternalDataExchange()> Public Interface IMyService
Sub FromWorkflow(ByVal Message As String)
Event ToWorkflowEvent As EventHandler(Of MyEventArgs)
End Interface
<Serializable()> Public Class MyService
Implements IMyService
<NonSerialized()> Dim _Target As System.ComponentModel.ISynchronizeInvoke
<NonSerialized()> Dim _Callback As EventHandler(Of MyEventArgs)
Public Sub New(ByVal Target As System.ComponentModel.ISynchronizeInvoke, _
ByVal Callback As EventHandler(Of MyEventArgs))
_Target = Target
_Callback = Callback
End Sub
Public Sub FromWorkflow(ByVal Message As String) Implements IMyService.FromWorkflow
_Target.Invoke(_Callback, New Object() {Me, New MyEventArgs(Guid.Empty, Message)})
End Sub
Public Event ToWorkflowEvent(ByVal sender As Object, ByVal e As MyEventArgs) Implements IMyService.ToWorkflowEvent
Public Sub RaiseMessageToWorkflow(ByVal InstanceId As Guid, ByVal Message As String)
RaiseEvent ToWorkflowEvent(Me, New MyEventArgs(InstanceId, Message))
End Sub
End Class
End Namespace
Application Form
Public Class Test
'variabile che contiene il Runtime del Framework di Workflow
Public objWorkflowRuntime As WorkflowRuntime
'Variabile che contiene l'istanza al Servizio Workflow presente nella libreria WorkflowInterface
Public objWorkflowService As MyService
'variabile che contiene l'istanza al Workflow
Public objWorkflowInstance As WorkflowInstance
Private Sub Test_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
objWorkflowRuntime = New WorkflowRuntime() 'Creo il Runtime del Workflow
Dim extDataService As New ExternalDataExchangeService() 'Creo il servizio che implementa l'interfaccia condivisa con il workflow
objWorkflowRuntime.AddService(extDataService) 'Passo il servizio al Runtime
Dim CallBack As New EventHandler(Of MyEventArgs)(AddressOf ReturnCallbackMessage)
objWorkflowService = New MyService(Me, CallBack)
objWorkflowRuntime.AddService(objWorkflowService)
objWorkflowRuntime.StartRuntime()
End Sub
Public Sub ReturnCallbackMessage(ByVal sender As Object, ByVal e As MyEventArgs)
Log.AppendText(e.Message & vbCrLf)
End Sub
Private Sub Starter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Starter.Click
objWorkflowInstance = objWorkflowRuntime.CreateWorkflow(GetType(Workflow.Workflow1))
objWorkflowInstance.Start()
End Sub
Private Sub Request_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Request.Click
objWorkflowService.RaiseMessageToWorkflow(objWorkflowInstance.InstanceId, Me.Name)
End Sub
End Class
Grazie
Max
Modificato da maxblli2 il 15 novembre 2007 19.59 -