Bonjour bonjour,

Je suis débutant en C# est je m'attaque a un projet plutôt complexe.

Le but de mon projet est de lire un fichier XML, le parser, et envoyer les données sur un WebService pour que mes données soit traitées et stockées dans une BDD par celui-ci.

J'ai donc deux projet un type console, est un ASP.NET contenant mon WEBService (ServiceStack).

Mon problème se pose lorsque j'essaye de "poster" une donnée, j'ai matte plein de tutos mais je ne sais pas trop a quoi va ressembler ma réponse ou le succès de mon "postage". D’après ce que j'ai compris je devrais recevoir sur ma console une réponse si mon information a été posté.

Deuxième problème, comment envoyer toute les infos de mon fichier xml en un coup, sachant que j'ai déjà de-sérialiser mon fichier? Je n'ai vraiment aucune idée de la marche a suivre.

Je vous met mon code console pour le post:
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
/// ------------------- POST ----------------------
///
 
//string url = "http://localhost:55867/xml/reply/Gateway_Registration_Payload";
//string xml_data = LHRP.Device_Info.Type;
 
HttpWebRequest httpWReq =
    (HttpWebRequest)WebRequest.Create("http://localhost:55867/xml/reply/Gateway_Registration_Payload");
 
ASCIIEncoding encoding = new ASCIIEncoding();
string postData = "username=user";
postData += "&password=pass";
byte[] data = encoding.GetBytes(postData);
 
httpWReq.Method = "POST";
httpWReq.ContentType = "application/x-www-form-urlencoded";
httpWReq.ContentLength = data.Length;
 
using (Stream stream = httpWReq.GetRequestStream())
{
    stream.Write(data, 0, data.Length);
}
 
HttpWebResponse response = (HttpWebResponse)httpWReq.GetResponse();
 
string responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
Mon code web service ressemble a ca:
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
/// <summary>
///     Define your ServiceStack web service request (i.e. Request DTO).
/// </summary>
/// <remarks>The route is defined here rather than in the AppHost.</remarks>
[Api("GET or DELETE a single movie by Id. Use POST to create a new Gateway_Registration_Payload and PUT to update it")]
[Route("/Gateway_Registration_Payload", "POST,PUT,PATCH,DELETE")]
[Route("/Gateway_Registration_Payload/{Id}")]
public class Gateway_Registration_Payload : IReturn<Gateway_Registration_Payload_Response>
{
    /// <summary>
    ///     Initializes a new instance of the movie.
    /// </summary>
    public Gateway_Registration_Payload()
    {
        this.Genres = new List<string>();
    }
    /// <summary>
    ///     Gets or sets the id of the movie. The id will be automatically incremented when added.
    /// </summary>
    [AutoIncrement]
    public int Id { get; set; }
 
    public int SessionID { get; set; }
    public List<string> Genres { get; set; }
}
 
/// <summary>
///     Define your ServiceStack web service response (i.e. Response DTO).
/// </summary>
public class Gateway_Registration_Payload_Response
{
    /// <summary>
    ///     Gets or sets the movie.
    /// </summary>
    public Gateway_Registration_Payload Gateway_Registration_Payload { get; set; }
}
 
/// <summary>
///     Create your ServiceStack restful web service implementation.
/// </summary>
public class Gateway_Registration_Payload_Service : Service
{
    /// <summary>
    ///     GET /Gateway_Registration_Payload/{Id}
    /// </summary>
    public Gateway_Registration_Payload_Response Get(Gateway_Registration_Payload Gateway_Registration_Payload)
    {
        return new Gateway_Registration_Payload_Response
                   {
                       Gateway_Registration_Payload = Db.Id<Gateway_Registration_Payload>(Gateway_Registration_Payload.Id),
                   };
    }
 
    /// <summary>
    ///     POST /Gateway_Registration_Payload
    ///     returns HTTP Response =>
    ///     201 Created
    ///     Location: http://localhost/ServiceStack.MovieRest/Gateway_Registration_Payload/{newGateway_Registration_PayloadId}
    ///     {newMovie DTO in [xml|json|jsv|etc]}
    /// </summary>
    public object Post(Gateway_Registration_Payload Gateway_Registration_Payload)
    {
        Db.Insert(Gateway_Registration_Payload);
        var newGateway_Registration_PayloadId = Db.GetLastInsertId();
 
        var newGateway_Registration_Payload = new Gateway_Registration_Payload_Response
                           {
                               Gateway_Registration_Payload = Db.Id<Gateway_Registration_Payload>(newGateway_Registration_PayloadId),
                           };
 
        return new HttpResult(newGateway_Registration_Payload)
                   {
                       StatusCode = HttpStatusCode.Created,
                       Headers =
                           {
                               {HttpHeaders.Location, base.Request.AbsoluteUri.CombineWith(newGateway_Registration_PayloadId.ToString())}
                           }
                   };          
    }
 
    /// <summary>
    ///     PUT /Gateway_Registration_Payload/{id}
    /// </summary>
    public object Put(Gateway_Registration_Payload Gateway_Registration_Payload)
    {
        Db.Update(Gateway_Registration_Payload);
 
        return new HttpResult
                   {
                       StatusCode = HttpStatusCode.NoContent,
                       Headers =
                           {
                               {HttpHeaders.Location, this.RequestContext.AbsoluteUri.CombineWith(Gateway_Registration_Payload.Id.ToString())}
                           }
                   };
    }
 
    /// <summary>
    ///     DELETE /Gateway_Registration_Payload/{Id}
    /// </summary>
    public object Delete(Gateway_Registration_Payload request)
    {
        Db.DeleteById<Gateway_Registration_Payload>(request.Id);
 
        return new HttpResult
                   {
                       StatusCode = HttpStatusCode.NoContent,
                       Headers =
                           {
                               {HttpHeaders.Location, this.RequestContext.AbsoluteUri.CombineWith(request.Id.ToString())}
                           }
                   };
    }
}
Merci d'avance pour votre aide,
N’hésitez pas a me re-poser des questions je ne pense pas avoir été très clair dans mon sujet.
Benmaster1