Bonjour,
je travaille actuellement sur un projet qui consiste à envoyer un document Word généré par l'application Win Forms Via un web Service. à présent je fais mes premiers pas avec les web services et je suis à cours d'informations !
j'ai commencé par des tests en local du coup j'ai créé un mock service soap avec le logiciel SOAP UI et j'ai testé sur ce Logiciel, ce que je POST est bien recu !
Là je passe à l'étape suivante qui consisterait à envoyer une simple information ' numéro de commande' à titre d'exemple, j'ai fait quelques lignes de commandes notamment exposé sur la documentation C# mais j'ai plusieurs erreurs !
je ne sais pas si c'est à cause du 'Mock Service' ou problème du codage !
Je vous remercie d'avance pour votre réponse !
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 namespace testWebService { class WebRequestPost { public static void Main() { // Create a request using a URL that can receive a post. WebRequest request = WebRequest.Create("http://localhost:8088/mockOrder?WSDL"); // Set the Method property of the request to POST. request.Method = "POST"; // Create POST data and convert it to a byte array. string postData = "Order012"; byte[] byteArray = Encoding.UTF8.GetBytes(postData); // Set the ContentType property of the WebRequest. request.ContentType = "text/xml; charset=utf-8"; // Set the ContentLength property of the WebRequest. request.ContentLength = byteArray.Length; // Get the request stream. Stream dataStream = request.GetRequestStream(); // Write the data to the request stream. dataStream.Write(byteArray, 0, byteArray.Length); // Close the Stream object. dataStream.Close(); // Get the response. WebResponse response = request.GetResponse(); // Display the status. Console.WriteLine(((HttpWebResponse)response).StatusDescription); // Get the stream containing content returned by the server. // The using block ensures the stream is automatically closed. using (dataStream = response.GetResponseStream()) { // Open the stream using a StreamReader for easy access. StreamReader reader = new StreamReader(dataStream); // Read the content. string responseFromServer = reader.ReadToEnd(); // Display the content. Console.WriteLine(responseFromServer); } // Close the response. response.Close(); } } }
Partager