locked
WCF REST API - Access client FORM fields value at EndPoint(POST operation) RRS feed

  • Question

  • User313764879 posted

    I just jumped into WCF REST API programming and is facing a situation. Would really appreciate some tips and suggestions.

    #1 My Client is a asp.net for now. It could be CF/ASP anything later:
    ----------------------------------------------------------------------------------------
    HttpClient http = new HttpClient(http://localhost:1260/RestServiceImpl.svc/);
    string strCustomer = @"<Customer>...</Customer>";
    HttpResponseMessage resp = null;
    HttpUrlEncodedForm form = new HttpUrlEncodedForm();
    form.Add(
    "CustomerXML", strCustomer);
    System.Net.
    ServicePointManager.Expect100Continue = false;
    resp = http.Post(
    "post/test", "text/xml",
    form.CreateHttpContent());
    resp.EnsureStatusIsSuccessful();
    ----------------------------------------------------------------------------------------


    #2 IRestServiceImpl.cs:
    ----------------------------------------------------------------------------------------
    [OperationContract]
    [WebInvoke(Method =
    "POST",
    UriTemplate =
    "post/{id}")]
    string Update(string id);
    ---------------------------------------------------------------------------------------- <u1:u1:u1:p></u1:u1:u1:p><o:o:o:p></o:o:o:p>

    #3 RestServiceImpl.cs:
    ----------------------------------------------------------------------------------------
    public string Update(string id)
    {
    return "the client submitted this: " + id;
    } <u1:u1:u1:p></u1:u1:u1:p>
    <o:o:o:p></o:o:o:p>

    COMMENTS:

    When I run the client, I was able to hit the #3 method Update(...) through the
    .net debugger. But I have no idea on how to extract the #1 POSTED HTML FORM
    data inside #3. How to get "
    CustomerXML" form
    field value sent from #1 ?


    Advice would really be appreciated
    ----------------------------------------------------------------------------------------

    Tuesday, April 5, 2011 11:38 AM

Answers

  • User313764879 posted

    Thanks Peter for the information. By then, I have managed to do it some other way around something like this:

    public string Update(Stream input)
            {
                StreamReader sr = new StreamReader(input);
                string s = sr.ReadToEnd();
                sr.Dispose();
                NameValueCollection qs = HttpUtility.ParseQueryString(s);
                string apikey = qs["apikey"];
                string xmldata = qs["xmldata"];
                return xmldata;
            }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, April 7, 2011 8:54 AM

All replies