Bonjour,

Je mets en place mon premier service wcf et je galère à appeler ma méthode depuis le serveur sous lequel le service est hébergé. Lorsque j'essaye d'appeler ma méthode, rien ne se passe. Dans l'interface cliente j'arrive jusqu'au niveau de la ligne suivante:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
                    channel.positionsgps();
J'ai l'impression d'appeler ma méthode en local. Mon Web.Config est configuré de la manière suivante:
Code XML : 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
<?xml version="1.0"?>
<configuration>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IService1"/>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://ks397287.kimsufi.com:8898/service1/Service1.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1" contract="WcfService1.IService1" name="BasicHttpBinding_IService1"/>
    </client>
  </system.serviceModel>
  <system.web>
    <compilation debug="true"/>
  </system.web>
</configuration>
.

Dans le fichier IService1.cs, j'appelle ma méthode de la manière suivante:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
[ServiceContract]
    public interface IService1
    {
 
        [OperationContract]
         List<string> positionsgps();
Le fichier Service1.svc:
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
    public class Service1 : IService1
    {
        public List<string> positionsgps()
        {
            string results = "";
            string pathtest = "";
            string[] donnees = new string[6];
            DirectoryInfo diTop = new DirectoryInfo(@"C:\log\");
            Dictionary<int, string> valeurs = new Dictionary<int, string>();
            List<string> lat = new List<string>();
            List<string> lon = new List<string>();
            List<string> name = new List<string>();
            List<string> resultats = new List<string>();
            try
            {
                foreach (var di in diTop.EnumerateDirectories("*"))
                {
                    try
                    {
                        foreach (var fi in di.GetFiles("*", SearchOption.AllDirectories))
                        {
                            if (!(fi.FullName.Contains("prog.csv")) && !(fi.FullName.Contains("trameNonGere.csv")))
                            {
                                string[] lines = System.IO.File.ReadAllLines(fi.FullName);
 
                                long FindLastLinePosition(BinaryReader br3, long start)
                                {
                                    br3.BaseStream.Position = start;
                                    char current = br3.ReadChar();
                                    while (!(current.Equals('\n')))
                                    {
                                        start -= 1;
                                        br3.BaseStream.Position = start;
                                        current = br3.ReadChar();
                                    }
                                    return (start + 1);
                                }
                                long WithoutReturnPosition(BinaryReader br2)
                                {
                                    long index = br2.BaseStream.Length - 1;
                                    br2.BaseStream.Position = index;
                                    int current = (int)br2.ReadChar();
                                    while ((current == 10) || (current == 13))
                                    {
                                        index -= 1;
                                        br2.BaseStream.Position = index;
                                        current = (int)br2.ReadChar();
                                    }
                                    return (index - 1);
                                }
 
                                string path = fi.FullName;
                                BinaryReader br = null;
                                StreamReader sr = null;
                                long position;
 
                                br = new BinaryReader(File.Open(path, FileMode.Open));
                                position = WithoutReturnPosition(br);
                                position = FindLastLinePosition(br, position);
                                br.Close();
                                sr = new StreamReader(File.Open(path, FileMode.Open));
                                sr.BaseStream.Position = position;
                                MatchCollection matches = Regex.Matches(sr.ReadLine(), "(?<val>.*[;])(?<date>[0-9]*[/][0-9]*[/][0-9]{4}.)(?<heu>[0-9]{2}[:][0-9]{2})(?<mes>.*[OK][;][0-9]*[;])(?<nom>.*)(?<reseau>[;].*)(?<autre>[;].*[;].*[;].*)(?<lat>[1-3]{1}[.][0-9]*)(?<vir>[,])(?<lon>[3-5]{1}[7-9]{1}[.][0-9]*)", RegexOptions.ExplicitCapture);
                                foreach (Match match in matches)
                                {
                                    results = di.Name.Replace("_", "/") + " " + fi.Name.Substring(0, 10) + "  " + match.Groups["date"].Value + "  " + match.Groups["heu"].Value + "  " + match.Groups["nom"].Value + "  " + match.Groups["lat"].Value + "  " + match.Groups["lon"].Value;
                                    Console.WriteLine(sr.ReadLine() + " " + results);
                                    donnees[1] = match.Groups["nom"].Value;
                                    donnees[2] = match.Groups["lat"].Value.ToString();
                                    donnees[3] = match.Groups["lon"].Value.ToString();
 
                                    if (!(name.Contains(donnees[1]) && lon.Contains(donnees[3]) && lat.Contains(donnees[2])))
                                    {
                                        lat.Add(donnees[2]);
                                        lon.Add(donnees[3]);
                                        name.Add(donnees[1]);
                                    }
                                    resultats.Add(results);
 
                                }
                                int row = 0;
                                int rowIndex = 0;
                                XElement document = new XElement("Document");
                                for (row = 0; row < name.Count; row++)
                                {
                                    if (rowIndex <= name.Count)
                                    {
                                        rowIndex++;
                                        if (lat.ToString() != "" && lon.ToString() != "")
                                        {
                                            document.Add(
                                            new XElement("Placemark",
                                            new XElement("name", name[row]),
                                            new XElement("Point",
                                            new XElement("coordinates", lat[row] + "," + lon[row]
                                        ))));
                                        }
                                    }
                                }
                                pathtest = @"C:\TDE\WcfService1\position_gps.kml";
                                System.IO.File.WriteAllText(pathtest, document.ToString());
WebClient wc = new WebClient();
            wc.DownloadFile("http://ks397287.kimsufi.com:8898/position_gps.kml", "C:\\log\\position_gps.kml");
 
                                sr.Close();
                            }
                        }
                    }
                    catch (UnauthorizedAccessException unAuthSubDir)
                    {
                        Console.WriteLine($"unAuthSubDir: {unAuthSubDir.Message}");
                    }
                }
 
            }
            catch (DirectoryNotFoundException dirNotFound)
            {
                Console.WriteLine($"{dirNotFound.Message}");
            }
 
            catch (UnauthorizedAccessException unAuthDir)
            {
                Console.WriteLine($"unAuthDir: {unAuthDir.Message}");
            }
 
            catch (PathTooLongException longPath)
            {
                Console.WriteLine($"{longPath.Message}");
            }
            return resultats;
        }
Et depuis l'interface utilisateur, voici comment j'appelle ma méthode:
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
static void Main(string[] args)
        {
            WebServiceHost host = new WebServiceHost(typeof(Service1));
            try
            {
                ServiceEndpoint ep = host.AddServiceEndpoint(typeof(WcfService1.IService1), new BasicHttpBinding(), "http://ks397287.kimsufi.com:8898/service1/Service1.svc");
                host.Open();
 
                using (ChannelFactory<WcfService1.IService1> cf = new ChannelFactory<WcfService1.IService1>(new BasicHttpBinding(), "http://ks397287.kimsufi.com:8898/service1/Service1.svc"))
                {
 
                    WcfService1.IService1 channel = cf.CreateChannel();
                    channel.positionsgps();
...
 host.Close();
Fichier service1.cs:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
public interface IService1
{
 
    [System.ServiceModel.OperationContractAttribute(Action = "http://ks397287.kimsufi.com:8898/service1/Service1.svc/positiongps", ReplyAction = "http://ks397287.kimsufi.com:8898/service1/Service1.svc/positiongps")]
    List<string> positionsgps();
 
 
}
Déjà est-ce que ces éléments vous semblent corrects? D'avance merci beaucoup pour vos réponses.

Elodie