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 7978979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:38:25+00:00 2026-06-04T09:38:25+00:00

I am trying to POST JSON to a WCF service. The json object contains

  • 0

I am trying to POST JSON to a WCF service. The json object contains an array. I’m wondering how to correctly bind to my data contract. If anyone can give me a pointer here I would really appreciate it. Currently my cart object is null

This is what my service interface looks like:

public interface IService
 {

[OperationContract]
 [WebInvoke(UriTemplate = "/cart", Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, RequestFormat = WebMessageFormat.Json,ResponseFormat = WebMessageFormat.Json)]
 Ship GetShipInfo( Cart cart, string Website);
 }

[DataContract]
 public class Cart
 {
 [DataMember]
 public Int32 ProductID { get; set;}
 [DataMember]
 public decimal ItemPrice { get; set; }
 [DataMember]
 public Int16 Qty { get; set; }
 [DataMember]
 public String SizeWidth { get; set; }
 }

My Client call is as follows

CLIENT CALL

using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Web;
 using System.Web.UI;
 using System.Web.UI.WebControls;
 using System.Runtime.Serialization.Json;
 using System.Net;
 using System.IO;

public partial class _Default : System.Web.UI.Page
 {
 protected void Page_Load(object sender, EventArgs e)
 {

DataContractJsonSerializer obj = new DataContractJsonSerializer(typeof(string));
 Cart cart = new Cart{ ProductID = 1000, ItemPrice = Convert.ToDecimal(32.50), Qty = 1, SizeWidth = “6M” };
 WebClient Proxy1 = new WebClient();
 Proxy1.Headers["Content-type"] = “application/json”;
 MemoryStream ms = new MemoryStream();
 DataContractJsonSerializer serializerToUplaod = new DataContractJsonSerializer(typeof(Cart));
 serializerToUplaod.WriteObject(ms, cart);

 byte[] data = Proxy1.UploadData(“http://localhost:54897/IphoneService.svc/cart”, “POST”, ms.ToArray());
 Stream stream = new MemoryStream(data);
 obj = new DataContractJsonSerializer(typeof(Ship));
 var Ship = obj.ReadObject(stream) as Ship;

}

public class Ship
 {
 public Decimal SecondDay { get; set; }
 public Decimal NextDay { get; set; }
 }

public class Cart
 {

public Int32 ProductID { get; set; }

public Decimal ItemPrice { get; set; }

public Int16 Qty { get; set; }

public String SizeWidth { get; set; }
 }

}

My JSON looks like this

{"cart":
[
{"ProductID":2957,
"Qty":1,
"ItemPrice":60,
"SizeWidth":"5M"}
]
}
  • 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-06-04T09:38:26+00:00Added an answer on June 4, 2026 at 9:38 am

    The raw request for your WCF REST method should look as below from Fiddler:

    POST http://localhost:54897/IphoneService.svc/cart HTTP 1.1
    Content-Type: application/json
    Host: localhost
    
    {"cart":{"ProductID":1,"ItemPrice":60,"Qty":1,"SizeWidth":"5M"},"Website":"sample website"}
    

    The response in JSON would look as below:

    HTTP/1.1 200 OK
    Content-Type: application/json
    Content-Length: 30
    
    {"SecondDay":5.0, "NextDay":7.0}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to POST JSON to a WCF service. The json object contains
I am trying to post data to WCF REST service and I keep getting
I'm trying to POST a serialized object to my WCF service. However, I keep
I'm currently trying to post a JSON object from my view to my controller
I'm trying to post a JavaScript data object with the following: $.post(frm.attr(action), data, function(res)
I'm trying to post a JSON object through a POST. I'm trying to do
I am trying to build a REST & json based WCF service that takes
I am trying to make a post request to my restful WCF service. The
I am having problems trying to POST a JSON Array. For my Android code,
I'm trying to contact a RESTful WCF POST web service from an android client

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.