Bonjour,
Je suis entrain de créer un petit web service afin de le consommer depuis un pocket pc.
voici le code du WS :
J'ai ajouté la référence du WS au projet ppc et voici le code de la classe consommatrice:
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 using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Services; namespace WebServicesHTTPS { [WebService(Namespace = "http://192.168.1.7:3551/Service1.asmx")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] public class Service1 : System.Web.Services.WebService { [WebMethod] public int AddInteger(int a, int b) { return a + b; } } }
Sachant que le WS est accessible en localhost à partir de "http://localhost:3551/Service1.asmx" et qu'il fonctionne depuis une application Windows local, je voulais donc savoir si j'ai zappé une étape pour l'accès a distance.
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 using System; using System.Linq; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace testWebServices { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { try { textBox3.Text = "debut"; localhost.Service1 serviceAdd = new localhost.Service1(); // Conversion des valeurs String en int int a = Int32.Parse(textBox1.Text); int b = Int32.Parse(textBox2.Text); // Appel à la méthode distante. Son résultat étant un int, on le convertit en String textBox3.Text = serviceAdd.AddInteger(a, b).ToString(); } catch { textBox3.Text = "Erreur"; } } } }
Merci d'avance
Partager