IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C# Discussion :

Quels namespace pour IServerContractCallback et ServerContractClient?


Sujet :

C#

  1. #1
    Membre actif Avatar de Masmeta
    Homme Profil pro
    Ing. R&D informatique industrielle
    Inscrit en
    Mai 2006
    Messages
    472
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Ing. R&D informatique industrielle
    Secteur : Industrie

    Informations forums :
    Inscription : Mai 2006
    Messages : 472
    Points : 221
    Points
    221
    Par défaut Quels namespace pour IServerContractCallback et ServerContractClient?
    Bonjour à tous ,

    J'étudie l'article "Développer une visionneuse d'images avec WPF et WCF" sur Tech Head Brother, posté par Thomas Lebrun.
    J'essaye de comprendre ce code cependant je bloque sur les déclarations du client et surtout sur :
    1. public class WCFClient : IServerContractCallback quelque est le namespace de IServerContractCallback ?
    2. private ServerContractClient sc = null; : Quel est le namespace de ServerContractClient?

    J'ai cherché sur la MSDN en framework 4, cependant je n'ai rien trouvé.

    Pouvez vous m'éclairez sur ses deux points?
    Je vous remercie,

  2. #2
    Invité
    Invité(e)
    Par défaut
    L'auteur du tutoriel ne définie pas de Namespace pour les classes spécifiées. Il n'a mis que les définitions des classes que tu as citées. Tu copies ces classes dans ton projet avec le namespace que tu veux et tu utilises celui-ci tout au long du tuto.

  3. #3
    Membre actif Avatar de Masmeta
    Homme Profil pro
    Ing. R&D informatique industrielle
    Inscrit en
    Mai 2006
    Messages
    472
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Ing. R&D informatique industrielle
    Secteur : Industrie

    Informations forums :
    Inscription : Mai 2006
    Messages : 472
    Points : 221
    Points
    221
    Par défaut
    Citation Envoyé par h2s84 Voir le message
    L'auteur du tutoriel ne définie pas de Namespace pour les classes spécifiées. Il n'a mis que les définitions des classes que tu as citées. Tu copies ces classes dans ton projet avec le namespace que tu veux et tu utilises celui-ci tout au long du tuto.
    C'est ce que j'ai fait mais j'ai cette erreur que je ne comprend pas

  4. #4
    Invité
    Invité(e)
    Par défaut
    Citation Envoyé par Masmeta Voir le message
    C'est ce que j'ai fait mais j'ai cette erreur que je ne comprend pas
    Sauf que nous tu nous as toujours pas fourni l'erreur dont tu parles

  5. #5
    Membre expert


    Homme Profil pro
    Développeur informatique
    Inscrit en
    Avril 2006
    Messages
    970
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2006
    Messages : 970
    Points : 3 304
    Points
    3 304
    Par défaut
    h2s84 :-)

    Ca fait 10 minutes que je relis la discussion en me disant que je suis aveugle

  6. #6
    Membre actif Avatar de Masmeta
    Homme Profil pro
    Ing. R&D informatique industrielle
    Inscrit en
    Mai 2006
    Messages
    472
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Ing. R&D informatique industrielle
    Secteur : Industrie

    Informations forums :
    Inscription : Mai 2006
    Messages : 472
    Points : 221
    Points
    221
    Par défaut
    Excusez moi, je me suis mal exprimé. Les erreurs que me fournissent VS2010 sont les suivantes :
    The type or namespace name 'ServerContractClient' could not be found (are you missing a using directive or an assembly reference?)

    The type or namespace name 'IServerContractCallback' could not be found (are you missing a using directive or an assembly reference?)
    C'est pour cela que je me demandais quels sont les namespaces de ses classes.

    Je joins mon code, ca peut aider aussi . J'ai uniquement fais du copier-coller du site avec des rajouts namespaces de Runtime .
    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
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
     
    using System.Text;
    using System.IO;
    using System.ServiceModel;
    using System.Runtime;
    using System.Runtime.Serialization;
    using System.Runtime.Remoting;
    namespace test_1
    {
      [ServiceContract]
        public interface IClientContract
        {
            [OperationContract(IsOneWay = true)]
            void GetImagesFromServer(List<CustomImage> img);
     
            [OperationContract(IsOneWay = true)]
            void GetUpdateFromFileShare(CustomImage img);
        }
     
     
        [ServiceContract(CallbackContract = typeof(IClientContract))]
        public interface IServerContract
        {
            [OperationContract(IsOneWay = false)]
            void StartWatcher(string path);
     
            [OperationContract(IsOneWay = false)]
            void GetImagesFromPathAtFirstLoad(string path);
        }
     
        [DataContract]
        public class CustomImage
        {
            public enum ChangeType
            {
                Add,
                Delete
            }
     
            [DataMember]
            public string Name { get; set; }
     
            [DataMember]
            public string FullPath { get; set; }
     
            [DataMember]
            public Byte[] Img { get; set; }
     
            [DataMember]
            public ChangeType Modification { get; set; }
        }
     
     
        [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.Single)]
        public class ServiceImplementation : IServerContract
        {
     
     
         #region Member Fields
     
            private System.IO.FileSystemWatcher fsw = null;
            private OperationContext context = null;
            private IClientContract client = null;
     
            #endregion
     
            #region IServerContract Members
     
            /// <summary>
            /// Start the FileSystemWatcher on the server.
            /// </summary>
            /// <param name="path">The path to the directory to watch.</param>
            public void StartWatcher(string path)
            {
                try
                {
                    context = OperationContext.Current;
                    client = context.GetCallbackChannel<IClientContract>();
     
                    fsw = new System.IO.FileSystemWatcher();
                    fsw.Path = path;
                    fsw.IncludeSubdirectories = true;
                    fsw.Filter = "*.*";
                    fsw.Created += new System.IO.FileSystemEventHandler(GetUpdateFileFromFSW);
                    fsw.Deleted += new System.IO.FileSystemEventHandler(GetUpdateFileFromFSW);
     
                    fsw.EnableRaisingEvents = true;
                }
                catch (Exception ex)
                {
                    throw new FaultException<ServerException>(new ServerException(
                        string.Format("An error occured !{0}{1}", Environment.NewLine, ex.Message)));
                }
            }
     
            /// <summary>
            /// Retrieve the images which are in the specified folder during the startup.
            /// </summary>
            /// <param name="path">The folder to get the images.</param>
            public void GetImagesFromPathAtFirstLoad(string path)
            {
                var imgList = new List<CustomImage>();
                CustomImage image = null;
     
                foreach (var file in Directory.GetFiles(path))
                {
                    try
                    {
                        if (Path.GetExtension(file).ToLower() == ".png" || Path.GetExtension(file).ToLower() == ".jpg" ||
                            Path.GetExtension(file).ToLower() == ".jpeg" || Path.GetExtension(file).ToLower() == ".bmp" ||
                            Path.GetExtension(file).ToLower() == ".gif")
                        {
                            using (var stream = File.OpenRead(file))
                            {
                                if (stream.Length > 0)
                                {
                                    image = new CustomImage();
     
                                    image.Name = Path.GetFileName(file);
                                    image.FullPath = Path.GetFullPath(file);
                                    image.Modification = CustomImage.ChangeType.Add;
                                }
                            }
     
                            byte[] array = GetByteFromImage(file);
                            image.Img = array;
     
                            imgList.Add(image);
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new FaultException<ServerException>(new ServerException(
                            string.Format("An error occured !{0}{1}", Environment.NewLine, ex.Message)));
                    }
                }
     
                if (client != null)
                {
                    client.GetImagesFromServer(imgList);
                }
            }
     
            #endregion
     
            /// <summary>
            /// Convert a file on a byte array.
            /// </summary>
            /// <param name="file">The file to convert.</param>
            /// <returns>An array of byte corresponding to the file.</returns>
            private static byte[] GetByteFromImage(string file)
            {
                byte[] array;
     
                try
                {
                    using (FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read))
                    {
                        BinaryReader reader = new BinaryReader(fs);
     
                        array = reader.ReadBytes((int)fs.Length);
     
                        reader.Close();
                    }
                }
                catch (Exception ex)
                {
                    throw new FaultException<ServerException>(new ServerException(
                        string.Format("An error occured !{0}{1}", Environment.NewLine, ex.Message)));
                }
     
                return array;
            }
     
            /// <summary>
            /// Method called when the FileSystemWatcher detects that a file has been added/deleted.
            /// </summary>
            private void GetUpdateFileFromFSW(object sender, System.IO.FileSystemEventArgs e)
            {
                CustomImage image = null;
     
                if (e.ChangeType == System.IO.WatcherChangeTypes.Created)
                {
                    if (File.Exists(e.FullPath) && (Path.GetExtension(e.FullPath).ToLower() == ".png" ||
                        Path.GetExtension(e.FullPath).ToLower() == ".jpg"
                        || Path.GetExtension(e.FullPath).ToLower() == ".jpeg" 
                        || Path.GetExtension(e.FullPath).ToLower() == ".bmp" 
                        || Path.GetExtension(e.FullPath).ToLower() == ".gif"))
                    {
                        try
                        {
                            using (var stream = File.OpenRead(e.FullPath))
                            {
                                if (stream.Length > 0)
                                {
                                    image = new CustomImage();
     
                                    image.Name = e.Name;
                                    image.FullPath = e.FullPath;
                                    image.Modification = CustomImage.ChangeType.Add;
                                }
                            }
     
                            byte[] array = GetByteFromImage(e.FullPath);
                            image.Img = array;
                        }
                        catch (Exception ex)
                        {
                            throw new FaultException<ServerException>(new ServerException(
                                string.Format("An error occured !{0}{1}", Environment.NewLine, ex.Message)));
                        }
                    }
                }
                else if (e.ChangeType == System.IO.WatcherChangeTypes.Deleted)
                {
                    image = new CustomImage();
     
                    image.Name = e.Name;
                    image.FullPath = e.FullPath;
                    image.Modification = CustomImage.ChangeType.Delete;
                }
     
                if (image != null)
                {
                    SendUpdateToClient(image);
                }
            }
     
            /// <summary>
            /// Inforl the client that an update is available.
            /// </summary>
            /// <param name="image">The image that have been added/deleted.</param>
            private void SendUpdateToClient(CustomImage image)
            {
                if (client != null)
                {
                    client.GetUpdateFromFileShare(image);
                }
            }
     
     
        }
     
        [CallbackBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, UseSynchronizationContext = false)]
        public class WCFClient : IServerContractCallback 
        {
            #region Member Fields
     
            private ServerContractClient sc = null;
     
            public delegate void GetImagesFromServerHandler(CustomImage[] imgList);
            public event GetImagesFromServerHandler GetImagesFromServerEvent;
     
            public delegate void GetUpdateFromFileShareHandler(CustomImage img);
            public event GetUpdateFromFileShareHandler GetUpdateFromFileShareEvent;
     
            #endregion
     
            /// <summary>
            /// Public constructor.
            /// </summary>
            public WCFClient()
            {
                sc = new ServerContractClient(new System.ServiceModel.InstanceContext(this));
     
                sc.Open();
            }
     
            /// <summary>
            /// Ask the service to launch the FileSystemWatcher on the server.
            /// </summary>
            /// <param name="path">The folder to watch on the server.</param>
            public void StartWatcher(string path)
            {
                sc.StartWatcher(path);
            }
     
            /// <summary>
            /// Ask the service to get the images which are in the dedicated folder.
            /// </summary>
            /// <param name="path">The folder that you want the images.</param>
            public void GetImagesFromPathAtFirstLoad(string path)
            {
                try
                {
                    sc.GetImagesFromPathAtFirstLoad(path);
                }
                catch (ServerException ex)
                {
                    throw new FaultException<ServerException>(new ServerException(
                        string.Format("An error occured !{0}{1}", Environment.NewLine, ex.Message)));
                }
            }
     
            /// <summary>
            /// Disconnect the client from the service.
            /// </summary>
            public void Disconnect()
            {
                sc.Close();
            }
     
            #region IServerContractCallback Members
     
            /// <summary>
            /// Method called when the service pushed the images to the client.
            /// </summary>
            /// <param name="imgList">The list of images to load/get from the server.</param>
            public void GetImagesFromServer(CustomImage[] imgList)
            {
                if (GetImagesFromServerEvent != null)
                {
                    GetImagesFromServerEvent(imgList);
                }
            }
     
            /// <summary>
            /// Method called when the service detext an update in the folder where the image are stored.
            /// </summary>
            /// <param name="img">The image that has been added/removed from the folder</param>
            public void GetUpdateFromFileShare(CustomImage img)
            {
                if (GetUpdateFromFileShareEvent != null)
                {
                    GetUpdateFromFileShareEvent(img);
                }
            }
     
            #endregion
        }
    }

  7. #7
    Invité
    Invité(e)
    Par défaut
    Les classes IServerContractCallback et ServerContractClient ne sont pas tombées du ciel comme ça. Tu les utilises dans ton code sans pour autant mettre dans ton code les définitions de ces dites classes. Ces classes comme dit plus haut sont à la page 2 du tutoriel. Ces deux classes ne sont pas de .Net mais créées par le développeur. Suis de A à Z le tutoriel en respectant les noms des classes fournies et normalement tu n'auras pas ce problème. Ensuite tu pourras renommer ces classes à ta sauce.

  8. #8
    Membre actif Avatar de Masmeta
    Homme Profil pro
    Ing. R&D informatique industrielle
    Inscrit en
    Mai 2006
    Messages
    472
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Ing. R&D informatique industrielle
    Secteur : Industrie

    Informations forums :
    Inscription : Mai 2006
    Messages : 472
    Points : 221
    Points
    221
    Par défaut
    Bonjour,
    Citation Envoyé par h2s84 Voir le message
    Suis de A à Z le tutoriel en respectant les noms des classes fournies et normalement tu n'auras pas ce problème. Ensuite tu pourras renommer ces classes à ta sauce.
    Je l'ai refais plusieurs fois soit dans ma solution ( un projet WCF Service et un projet WPF), ou dans une nouvelle solution. J'ai toujours le même soucis.

    La classe IServerContractCallback n'est pas IServerContract, et malgré mes différentes relectures, je ne l'a trouve pas dans le tuto, idem pour la classe ServerContractClient .

  9. #9
    Invité
    Invité(e)
    Par défaut
    C'est le même code que le tuto et peux-tu me dire ce qui ne marche pas ?
    Code C# : 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
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
     
    [ServiceContract(CallbackContract = typeof(IClientContract))]
        public interface IServerContract
        {
            [OperationContract(IsOneWay = false)]
            void StartWatcher(string path);
     
            [OperationContract(IsOneWay = false)]
            void GetImagesFromPathAtFirstLoad(string path);
        }
     
        [ServiceContract]
        public interface IClientContract
        {
            [OperationContract(IsOneWay = true)]
            void GetImagesFromServer(List<CustomImage> img);
     
            [OperationContract(IsOneWay = true)]
            void GetUpdateFromFileShare(CustomImage img);
        }
     
        [DataContract]
        public class CustomImage
        {
            public enum ChangeType
            {
                Add,
                Delete
            }
     
            [DataMember]
            public string Name { get; set; }
     
            [DataMember]
            public string FullPath { get; set; }
     
            [DataMember]
            public Byte[] Img { get; set; }
     
            [DataMember]
            public ChangeType Modification { get; set; }
        }
     
        [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.Single)]
        public class ServiceImplementation : IServerContract
        {
            #region Member Fields
     
            private System.IO.FileSystemWatcher fsw = null;
            private OperationContext context = null;
            private IClientContract client = null;
     
            #endregion
     
            #region IServerContract Members
     
            /// <summary>
            /// Start the FileSystemWatcher on the server.
            /// </summary>
            /// <param name="path">The path to the directory to watch.</param>
            public void StartWatcher(string path)
            {
                try
                {
                    context = OperationContext.Current;
                    client = context.GetCallbackChannel<IClientContract>();
     
                    fsw = new System.IO.FileSystemWatcher();
                    fsw.Path = path;
                    fsw.IncludeSubdirectories = true;
                    fsw.Filter = "*.*";
                    fsw.Created += new System.IO.FileSystemEventHandler(GetUpdateFileFromFSW);
                    fsw.Deleted += new System.IO.FileSystemEventHandler(GetUpdateFileFromFSW);
     
                    fsw.EnableRaisingEvents = true;
                }
                catch (Exception ex)
                {
                    throw new FaultException<ServerException>(new ServerException(
                        string.Format("An error occured !{0}{1}", Environment.NewLine, ex.Message)));
                }
            }
     
            /// <summary>
            /// Retrieve the images which are in the specified folder during the startup.
            /// </summary>
            /// <param name="path">The folder to get the images.</param>
            public void GetImagesFromPathAtFirstLoad(string path)
            {
                var imgList = new List<CustomImage>();
                CustomImage image = null;
     
                foreach (var file in Directory.GetFiles(path))
                {
                    try
                    {
                        if (Path.GetExtension(file).ToLower() == ".png" || Path.GetExtension(file).ToLower() == ".jpg" ||
                            Path.GetExtension(file).ToLower() == ".jpeg" || Path.GetExtension(file).ToLower() == ".bmp" ||
                            Path.GetExtension(file).ToLower() == ".gif")
                        {
                            using (var stream = File.OpenRead(file))
                            {
                                if (stream.Length > 0)
                                {
                                    image = new CustomImage();
     
                                    image.Name = Path.GetFileName(file);
                                    image.FullPath = Path.GetFullPath(file);
                                    image.Modification = CustomImage.ChangeType.Add;
                                }
                            }
     
                            byte[] array = GetByteFromImage(file);
                            image.Img = array;
     
                            imgList.Add(image);
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new FaultException<ServerException>(new ServerException(
                            string.Format("An error occured !{0}{1}", Environment.NewLine, ex.Message)));
                    }
                }
     
                if (client != null)
                {
                    client.GetImagesFromServer(imgList);
                }
            }
     
            #endregion
     
            /// <summary>
            /// Convert a file on a byte array.
            /// </summary>
            /// <param name="file">The file to convert.</param>
            /// <returns>An array of byte corresponding to the file.</returns>
            private static byte[] GetByteFromImage(string file)
            {
                byte[] array;
     
                try
                {
                    using (FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read))
                    {
                        BinaryReader reader = new BinaryReader(fs);
     
                        array = reader.ReadBytes((int)fs.Length);
     
                        reader.Close();
                    }
                }
                catch (Exception ex)
                {
                    throw new FaultException<ServerException>(new ServerException(
                        string.Format("An error occured !{0}{1}", Environment.NewLine, ex.Message)));
                }
     
                return array;
            }
     
            /// <summary>
            /// Method called when the FileSystemWatcher detects that a file has been added/deleted.
            /// </summary>
            private void GetUpdateFileFromFSW(object sender, System.IO.FileSystemEventArgs e)
            {
                CustomImage image = null;
     
                if (e.ChangeType == System.IO.WatcherChangeTypes.Created)
                {
                    if (File.Exists(e.FullPath) && (Path.GetExtension(e.FullPath).ToLower() == ".png" ||
                        Path.GetExtension(e.FullPath).ToLower() == ".jpg"
                        || Path.GetExtension(e.FullPath).ToLower() == ".jpeg"
                        || Path.GetExtension(e.FullPath).ToLower() == ".bmp"
                        || Path.GetExtension(e.FullPath).ToLower() == ".gif"))
                    {
                        try
                        {
                            using (var stream = File.OpenRead(e.FullPath))
                            {
                                if (stream.Length > 0)
                                {
                                    image = new CustomImage();
     
                                    image.Name = e.Name;
                                    image.FullPath = e.FullPath;
                                    image.Modification = CustomImage.ChangeType.Add;
                                }
                            }
     
                            byte[] array = GetByteFromImage(e.FullPath);
                            image.Img = array;
                        }
                        catch (Exception ex)
                        {
                            throw new FaultException<ServerException>(new ServerException(
                                string.Format("An error occured !{0}{1}", Environment.NewLine, ex.Message)));
                        }
                    }
                }
                else if (e.ChangeType == System.IO.WatcherChangeTypes.Deleted)
                {
                    image = new CustomImage();
     
                    image.Name = e.Name;
                    image.FullPath = e.FullPath;
                    image.Modification = CustomImage.ChangeType.Delete;
                }
     
                if (image != null)
                {
                    SendUpdateToClient(image);
                }
            }
     
            /// <summary>
            /// Inforl the client that an update is available.
            /// </summary>
            /// <param name="image">The image that have been added/deleted.</param>
            private void SendUpdateToClient(CustomImage image)
            {
                if (client != null)
                {
                    client.GetUpdateFromFileShare(image);
                }
            }

  10. #10
    Membre actif Avatar de Masmeta
    Homme Profil pro
    Ing. R&D informatique industrielle
    Inscrit en
    Mai 2006
    Messages
    472
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Ing. R&D informatique industrielle
    Secteur : Industrie

    Informations forums :
    Inscription : Mai 2006
    Messages : 472
    Points : 221
    Points
    221
    Par défaut
    Citation Envoyé par h2s84 Voir le message
    C'est le même code que le tuto et peux-tu me dire ce qui ne marche pas ?
    Ce code marche très bien. Je parle du code sur le client du service WCF

    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
     
     [CallbackBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, UseSynchronizationContext = false)]
        public class WCFClient : IServerContractCallback
        {
            #region Member Fields
     
            private ServerContractClient sc = null;
     
            public delegate void GetImagesFromServerHandler(CustomImage[] imgList);
            public event GetImagesFromServerHandler GetImagesFromServerEvent;
     
            public delegate void GetUpdateFromFileShareHandler(CustomImage img);
            public event GetUpdateFromFileShareHandler GetUpdateFromFileShareEvent;
     
            #endregion
     
            /// <summary>
            /// Public constructor.
            /// </summary>
            public WCFClient()
            {
                sc = new ServerContractClient(new System.ServiceModel.InstanceContext(this));
     
                sc.Open();
            }
     
            /// <summary>
            /// Ask the service to launch the FileSystemWatcher on the server.
            /// </summary>
            /// <param name="path">The folder to watch on the server.</param>
            public void StartWatcher(string path)
            {
                sc.StartWatcher(path);
            }
     
            /// <summary>
            /// Ask the service to get the images which are in the dedicated folder.
            /// </summary>
            /// <param name="path">The folder that you want the images.</param>
            public void GetImagesFromPathAtFirstLoad(string path)
            {
                try
                {
                    sc.GetImagesFromPathAtFirstLoad(path);
                }
                catch (ServerException ex)
                {
                    throw new FaultException<ServerException>(new ServerException(
                        string.Format("An error occured !{0}{1}", Environment.NewLine, ex.Message)));
                }
            }
     
            /// <summary>
            /// Disconnect the client from the service.
            /// </summary>
            public void Disconnect()
            {
                sc.Close();
            }
     
            #region IServerContractCallback Members
     
            /// <summary>
            /// Method called when the service pushed the images to the client.
            /// </summary>
            /// <param name="imgList">The list of images to load/get from the server.</param>
            public void GetImagesFromServer(CustomImage[] imgList)
            {
                if (GetImagesFromServerEvent != null)
                {
                    GetImagesFromServerEvent(imgList);
                }
            }
     
            /// <summary>
            /// Method called when the service detext an update in the folder where the image are stored.
            /// </summary>
            /// <param name="img">The image that has been added/removed from the folder</param>
            public void GetUpdateFromFileShare(CustomImage img)
            {
                if (GetUpdateFromFileShareEvent != null)
                {
                    GetUpdateFromFileShareEvent(img);
                }
            }
     
            #endregion
        }

Discussions similaires

  1. Quel est pour vous le meilleur éditeur xml ?
    Par neo.51 dans le forum XML/XSL et SOAP
    Réponses: 87
    Dernier message: 20/02/2010, 20h04
  2. Quel langage pour le développement embarqué ?
    Par freakydoz dans le forum Débats sur le développement - Le Best Of
    Réponses: 37
    Dernier message: 23/04/2007, 19h31
  3. Quel langage pour un application graphique sous windows
    Par ipeteivince dans le forum Langages de programmation
    Réponses: 7
    Dernier message: 06/06/2003, 17h00
  4. Quel Outil pour les applis Industrielles ET bases de données
    Par ThierryAIM dans le forum Débats sur le développement - Le Best Of
    Réponses: 8
    Dernier message: 23/04/2003, 09h14
  5. Quel outil pour du développement Client/Serveur (Win XP) ?
    Par jey_bonnet dans le forum Débats sur le développement - Le Best Of
    Réponses: 5
    Dernier message: 02/11/2002, 14h57

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo