Bonjour a tous,
Je débute deoucement la programmation de service WCF. J'ai d'ailleur suivi un petit tuto trouvé sur le web.
Cependant, j'ai un petit soucis avec la réception des messages envoyés par le service. J'arrive bien à les afficher via un MsgBox, mais en aucun cas les afficher dans une listview.
Merci pour vos réponses.
Voici les codes :
Le Serveur :
Et le client :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40 <ServiceBehavior(ConcurrencyMode:=ConcurrencyMode.Reentrant, InstanceContextMode:=InstanceContextMode.PerSession)> Public Class ArkCommServer Implements ArkServer Private client As ArkClient Sub New() client = OperationContext.Current.GetCallbackChannel(Of ArkClient)() End Sub Public Sub RunAction(ByVal action As String, ByVal taskname As String) Implements WCFLibrary.ArkServer.RunAction Try Select Case action Case "READ" SendMessage(1, "Action READ démarrée") Case "WRITE" SendMessage(1, "Action WRITE démarrée") Case Else SendMessage(2, "Action inconnue.") End Select Catch ex As Exception client.ReceiveMessage(2, ex.Message) End Try End Sub Public Sub SendMessage(ByVal type As Integer, ByVal message As String) Implements WCFLibrary.ArkServer.SendMessage Try Select Case type Case 1 'Information client.ReceiveMessage(1, "Réponse du serveur : " & message) Case 2 'Erreur client.ReceiveMessage(2, "Réponse du serveur : " & message) End Select Catch ex As Exception client.ReceiveMessage(2, ex.Message) End Try End Sub ... ...
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39 <CallbackBehavior(ConcurrencyMode:=ConcurrencyMode.Reentrant, UseSynchronizationContext:=False)> Public Class frmMain Implements ArkClient Public WCFService As ArkServer Sub New() WCFService = DuplexChannelFactory(Of ArkServer).CreateChannel(Me, New NetTcpBinding(), New EndpointAddress("net.tcp://127.0.0.1:1500)) End Sub Public Sub ReceiveMessage(ByVal type As Integer, ByVal message As String) Implements WCFLibrary.ArkClient.ReceiveMessage Try Select Case type Case 1 MsgBox(message, MsgBoxStyle.Information, "Information") '----->S'affiche bien Dim lv As New ListViewItem(New String() {"Information", Process.GetCurrentProcess.Id, message}, 0) Me.lvLogs.Items.Add(lv) '----->Ne s'affiche pas lv.Selected = True lv.EnsureVisible() End Select Catch ex As Exception msgbox(ex.Message) End Try End Sub Public Sub SendAction(ByVal action As String, ByVal taskname As String) Implements WCFLibrary.ArkClient.SendAction Try listview.items.add("Action envoyée au serveur : " & action) WCFService.RunAction(action, taskname) Catch ex As Exception msgbox(ex.Message) End Try End Sub .... ....
Partager