Bonjour,

Je reviens vous embeter avec mon service de calcul
J'ai réalisé un programme d'addition en interaction avec un service windows (du moins j'essaye) qui va récupérer les données entrées dans l'application, realiser les calculs et les renvoyer.

Mon probleme actuel est d'une que quand j'essaye de récupérer les informations que l'utilisateur rentre dans les textbox, je ne recupere rien (j'ai mis en bleu les textbox concernées) D'autre part (partie concernée en rouge), si je mets une valeur à la place des textsbox, que je l envoie pour qu'elle soit traitée par le service, quand elle revient je ne récupère qu'une chaine de caractère (string) vide Snif je suis perdu depuis hier. Voici le code de mon application :

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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
Public Class Form1
    Public Shared reception As New Threading.ManualResetEvent(False)


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim endpoint As Net.IPEndPoint

        Try


            'ip : 10.80.109.132 donne :'
            Dim iiip As Long = 16777343
            'ip localhost : 127.0.0.1'
            endpoint = New Net.IPEndPoint(iiip, 1039)

            Dim tutu As New Net.Sockets.TcpClient()
            tutu.BeginConnect("127.0.0.1", 1039, New AsyncCallback(AddressOf SendCallback), tutu)
            reception.WaitOne()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try



    End Sub

    Public Shared Sub SendCallback(ByVal ar As IAsyncResult)
        Dim tutu As Net.Sockets.TcpClient = CType(ar.AsyncState, Net.Sockets.TcpClient)
        tutu.EndConnect(ar)
        Dim Content(1024) As Byte
        Dim taa(1024) As Byte

        Dim n2 As String
        Dim nn As String
        Dim n1 As String
 n1 = form1.TextBox1.Text
        n2 = form1.TextBox2.Text
        nn = n1+"/"+n2
        'nn = "22/22" <== ca c quand je mets une valeur pour eviter le probleme des textbox' 


        Content = System.Text.Encoding.ASCII.GetBytes(nn.ToCharArray())
        Dim toto As Net.Sockets.NetworkStream = tutu.GetStream()
        toto.Write(Content, 0, Content.Length)
        toto.BeginRead(taa, 0, taa.Length, New AsyncCallback(AddressOf ReadCallback), toto)
    End Sub




    Public Shared Sub ReadCallback(ByVal ar As IAsyncResult)
        Dim toto As Net.Sockets.NetworkStream = CType(ar.AsyncState, Net.Sockets.NetworkStream)
        Dim myReadBuffer(2048) As Byte
        Dim ttt As Int32 = toto.EndRead(ar)
        Dim myCompleteMessage As String
        myCompleteMessage = System.Text.Encoding.ASCII.GetString(myReadBuffer, 0, ttt)
        Dim ttttttt As String = myCompleteMessage
    End Sub
   End Class

Et le code de mon windows service (il récupère bien les données envoyées par l'application et réalise les calculs, j'ai vérifié avec un fichier ou je lui demande de mettre le résultat) :

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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
 
Imports System.Net.sockets
Imports System
Imports System.Net
Imports System.Text
Imports System.Threading
Imports Microsoft.VisualBasic
Imports System.ServiceProcess.ServiceBase
 
Public Class Calcule
 
    Public Shared reception As New Threading.ManualResetEvent(False)
    Public Shared ev2 As New Threading.ManualResetEvent(False)
    Private listener As Net.Sockets.TcpListener
    Const PORT_NUM As Integer = 1039
    Dim EndPoint As Net.IPEndPoint
 
 
    Protected Overrides Sub OnStart(ByVal args() As String)
        Dim th As New System.Threading.Thread(AddressOf connec)
        th.isbackground = True
        th.Start()
 
    End Sub
 
 
    Public Sub connec()
        Try
            Dim iip As Long = 16777343
            EndPoint = New Net.IPEndPoint(iip, 1039)
            Dim listener As New TcpListener(EndPoint)
            listener.Start()
            reception.Reset()
            While True
                listener.BeginAcceptTcpClient(New AsyncCallback(AddressOf AcceptCallback), listener)
                reception.WaitOne()
            End While
 
        Catch ex As Exception
            Dim toto As System.IO.StreamWriter = New IO.StreamWriter("c:\data.txt")
            toto.Write(ex.Message)
            toto.Close()
        End Try
    End Sub
 
 
 
    Public Shared Sub AcceptCallback(ByVal ar As IAsyncResult)
        Try
            Dim bit(1024) As Byte
            Dim biit(1024) As Byte
            Dim ch1, ch2, ch3, ch4 As String
            Dim nb1, nb2, nb3 As Double
            Dim tab() As String
            ch1 = Nothing
            ch2 = Nothing
            ch3 = Nothing
 
            Dim listener As TcpListener = CType(ar.AsyncState, TcpListener)
            Dim client As TcpClient = listener.EndAcceptTcpClient(ar)
            Dim stream As NetworkStream = client.GetStream()
            stream.Read(bit, 0, bit.Length)
 
            ch1 = System.Text.Encoding.ASCII.GetString(bit, 0, bit.Length)
            tab = ch1.Split("/")
            ch2 = tab.GetValue(0)
            ch3 = tab.GetValue(1)
            nb1 = Double.Parse(ch2)
            nb2 = Double.Parse(ch3)
            nb3 = nb1 + nb2
            ch4 = nb3.ToString
            Try
                biit = System.Text.Encoding.ASCII.GetBytes(ch4.ToCharArray)
 
                stream.BeginWrite(biit, 0, biit.Length, New AsyncCallback(AddressOf WriteCallback), stream)
            Catch ex As Exception
                Dim taataaaa As System.IO.StreamWriter = New IO.StreamWriter("c:\error3.txt")
            End Try
 
            reception.Set()
 
            Dim tata As System.IO.StreamWriter = New IO.StreamWriter("c:\data2.txt")
            tata.AutoFlush = True
            tata.Write(ch4)
            tata.Close()
 
        Catch ex As Exception
            Dim taataaaa As System.IO.StreamWriter = New IO.StreamWriter("c:\error.txt")
        End Try
 
 
    End Sub
 
    Public Shared Sub WriteCallback(ByVal ar As IAsyncResult)
 
        Dim Stream As NetworkStream = CType(ar.AsyncState, NetworkStream)
 
        Stream.EndWrite(ar)
 
 
    End Sub
 
    Protected Overrides Sub OnStop()
        listener.Stop()
    End Sub
 
 
End Class

Merci d'avance pour l'aide que vous m'apporterez