Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7610479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:25:40+00:00 2026-05-31T01:25:40+00:00

I need to call my WCF REST Service with multiple parameters with the POST

  • 0

I need to call my WCF REST Service with multiple parameters with the POST method, but I can’t create DataContract containing my parameters because I need simple types : my webservice will be consumed by an objective C application.

I found this syntax on the MSDN site :

[OperationContract]
[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "savejson?id={id}&fichier={fichier}")]
bool SaveJSONData(string id, string fichier);

To explain quickly the context, I have to call this method to save a JSON file with the Id passed on a database.

My fisrt question is : is it really possible to pass several parameters to a POST method as shown before ?

Secondly : how can I do to consume my service (in C# for the moment, just to test it) with several parameters ?

I’ve already tested with DataContract, and I was doing like that :

string url = "http://localhost:62240/iECVService.svc/savejson";
        WebClient webClient = new WebClient();
        webClient.Headers["Content-type"] = "application/json; charset=utf-8";
        RequestData reqData = new RequestData { IdFichier = "15", Fichier = System.IO.File.ReadAllText(@"C:\Dev\iECV\iECVMvcApplication\Content\fichier.json") };
        MemoryStream requestMs = new MemoryStream();
        DataContractJsonSerializer requestSerializer = new DataContractJsonSerializer(typeof(RequestData));
        requestSerializer.WriteObject(requestMs, reqData);
        byte[] responseData = webClient.UploadData(url, "POST", requestMs.ToArray());
        MemoryStream responseMs = new MemoryStream(responseData);
        DataContractJsonSerializer responseSerializer = new DataContractJsonSerializer(typeof(ResponseData));
        ResponseData resData = responseSerializer.ReadObject(responseMs) as ResponseData;

RequestData and ResponseData were declared this way :

[DataContract(Namespace = "")]
public class RequestData
{
    [DataMember]
    public string IdFichier { get; set; }

    [DataMember]
    public string Fichier { get; set; }
}

[DataContract]
public class ResponseData
{
    [DataMember]
    public bool Succes { get; set; }
}

But as I said, I can’t do it like this anymore…

I hope I’m enough clear, if not, don’t hesitate to ask me details !

Thanks a lot for your help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T01:25:42+00:00Added an answer on May 31, 2026 at 1:25 am

    There are a few things you can do to avoid using data contracts. The simplest of them is to use a JSON DOM library which lets you create (and parse) JSON data as a tree, without having to convert them to existing classes. Two of them are the JSON.NET project (used in the sample code below), or the System.Json library (can be downloaded via NuGet). There are many JSON libraries for non-.NET languages as well.

    Another thing you can do to make your life simpler is to change the body style of the operation from Wrapped (which wraps the response) to Wrapped to WrappedRequest. The request needs to be wrapped, since you have two inputs, but the response doesn’t, so you can eliminate one step with that.

    public class Post_182e5e41_4625_4190_8a4d_4d4b13d131cb
    {
        [ServiceContract]
        public class Service
        {
            [OperationContract]
            [WebInvoke(Method = "POST",
                ResponseFormat = WebMessageFormat.Json,
                RequestFormat = WebMessageFormat.Json,
                BodyStyle = WebMessageBodyStyle.WrappedRequest,
                UriTemplate = "savejson")]
            public bool SaveJSONData(string id, string fichier)
            {
                return true;
            }
        }
    
        public static void Test()
        {
            string baseAddress = "http://" + Environment.MachineName + ":8000/Service";
            WebServiceHost host = new WebServiceHost(typeof(Service), new Uri(baseAddress));
            host.Open();
            Console.WriteLine("Host opened");
    
            JObject json = new JObject();
            json.Add("id", JToken.FromObject("15"));
            json.Add("Fichier", "the file contents"); //System.IO.File.ReadAllText(@"C:\Dev\iECV\iECVMvcApplication\Content\fichier.json"));
    
            WebClient c = new WebClient();
            c.Headers[HttpRequestHeader.ContentType] = "application/json";
            string result = c.UploadString(baseAddress + "/savejson", json.ToString(Newtonsoft.Json.Formatting.None, null));
            JToken response = JToken.Parse(result);
            bool success = response.ToObject<bool>();
            Console.WriteLine(success);
    
            Console.Write("Press ENTER to close the host");
            Console.ReadLine();
            host.Close();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using WCF to create some REST service. One of the Rest Service method
I call a WCF service from multiple threads at the same time, but the
I need to call a wcf service method in my project, if I have
Lame question but when you call a wcf service asynchronously, do you need to
i wish to create a repository pattern but with a WCF Rest Service which
A Silverlight 3.0 application tries to call WCF service but the application can not
So I'm trying to create a C# WCF REST service that is called by
I have a WCF service that I need to call. When I go through
I need to make call to a WCF service in a Transaction scope. I
On a scheduled interval I need to call a WCF service call another WCF

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.