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

  • SEARCH
  • Home
  • 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 5843333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:08:24+00:00 2026-05-22T12:08:24+00:00

I am trying to get my application working by using REST, WCF and JSON

  • 0

I am trying to get my application working by using REST, WCF and JSON (new to all those technologies). I have the ‘GET’ working fine. It is the ‘POST’ that is causing me problems.

As you will see below I ‘pack up’ my JSON using JSON.stringify, then fire off the POST to the REST resource. However, when the object gets to the WCF method that is handling the request the object is always null.

Here is the code:

$.ajax({
    type: "POST",
    dataType: "json",
    url: "Services/ContactCompanyService.svc/contactcompanies/customers",
    contentType: "application/json; charset=utf-8",
    data: JSON.stringify({ contactcompany: newCustomer }),
    success: function (html) { alert(html); }
});

Here is the config stuff:

<services>
  <service behaviorConfiguration="ServiceBehaviour" name="ContactCompanyService">
    <endpoint address="contactcompanies" behaviorConfiguration="web" binding="webHttpBinding" contract="IContactCompanyService"/>
  </service>

</services>

<behaviors>
  <endpointBehaviors>
    <behavior name="web">
      <webHttp/>
      <enableWebScript/>
    </behavior>
  </endpointBehaviors>
  <serviceBehaviors>
    <behavior name="ServiceBehaviour">
      <serviceMetadata httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="false"/>
    </behavior>
    <behavior name="">
      <serviceMetadata httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="false"/>
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true"/>

Here is the contract:

    [OperationContract]
    [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "customers")]
    [return: MessageParameter(Name = "ContactCompany")]
    ContactCompany AddContactCompany(ContactCompany ContactCompanyObject);

And it is the method that implements the above interface where ContactCompanyObject is null.

What on earth am I doing wrong? Please don’t rule out stupidity on my part.

Further:
I changed the WebMessageBodyStyle to .Bare, and this resulted in the object not being null … but EVERY property of the object being null. That said, wrapped is the way I would like to go.

I would be grateful of any assistance. Let me know if you need further information.

UPDATE

I started from scratch with a completely new project – stripped back.

I am getting exactly the same result – the object, when received by the WCF code, is null.

Here’s what I did on this new test project.

WCF Contract:

(under the namespace: NullTestService

[ServiceContract]
public interface IService1
{
    [OperationContract]
    [WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "NullTestPost")]
    [return: MessageParameter(Name = "NullTestType")]
    NullTestType GettMethod();

    [OperationContract]
    [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "NullTestPost")]
    [return: MessageParameter(Name = "NullTestType")]
    NullTestType PostMethod(NullTestType NullTestTypeObject);
}

[DataContract]
public class NullTestType
{
    [DataMember]
    public string NullTestString { get; set; }
    [DataMember]
    public int NullTestInt { get; set; }
}

Service Implementation:
(same namespace)

    public class Service1 : IService1
{
    public NullTestType PostMethod(NullTestType NullTestTypeObject)
    {
        return NullTestTypeObject;
    }

    public NullTestType GettMethod()
    {
        return new NullTestType { NullTestString = "Returned String", NullTestInt = 25 };
    }

}

Website project.
Service.svc:

<%@ ServiceHost Service="NullTestService.Service1" %>

web.config in the web project:

    <system.serviceModel>
<services>
  <service behaviorConfiguration="ServiceBehaviour" name="NullTestService.Service1">
    <endpoint address="nulltestaddress" behaviorConfiguration="web" binding="webHttpBinding" contract="NullTestService.IService1"/>
  </service>

</services>

<behaviors>
  <endpointBehaviors>
    <behavior name="web">
      <webHttp/>
    </behavior>
  </endpointBehaviors>
  <serviceBehaviors>
    <behavior name="ServiceBehaviour">
      <serviceMetadata httpGetEnabled="false" />
      <serviceDebug includeExceptionDetailInFaults="false"/>
    </behavior>
  </serviceBehaviors>
</behaviors>
</system.serviceModel>

and finally the jQuery in the web project:

$(function () {


//        $.ajax({
//            type: "GET",
//            url: "http://localhost:8080/TestWeb/Service.svc/nulltestaddress/nulltestpost",
//            success: alertResult
//        });

alert('about to do it');

$.ajax({
    type: "POST",
    url: "http://localhost:8080/TestWeb/Service.svc/nulltestaddress/nulltestpost",
    dataType: "json",
    contentType: "application/json; charset=utf-8",
    data: '{"NullTestType":{"NullTestString":"This is a post string","NullTestInt":25}}',
    success: alertResult
});

});

function alertResult(data) {
        alert(data.NullTestType.NullTestString);
}

So. The (commented out) GET works fine and returns the JSON. The POST does not. On the line:

public NullTestType PostMethod(NullTestType NullTestTypeObject)
{
    return NullTestTypeObject;
}

(the ‘return’ line) the NullTestTypeObject is always NULL.

I would be very grateful for help. I have lost a lot of time over this.

  • 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-22T12:08:25+00:00Added an answer on May 22, 2026 at 12:08 pm

    If Wrapped is what you want to do, then you need to wrap the request in the operation parameter name:

    var input = { "ContactCompanyObject" : newCustomer };
    $.ajax({
       data: input
       ...
    });
    

    Or for the second example, if you change the ajax call to the one shown below, you should get the expected result:

    var input = { NullTestTypeObject: { NullTestString: "Hello", NullTestInt: 123} };
    alert("Input: " + JSON.stringify(input));
    $.ajax({
        type: "POST",
        url: "./Service1.svc/nulltestaddress/NullTestPost",
        contentType: "application/json",
        data: JSON.stringify(input),
        success: function (result) {
            alert("POST result: " + JSON.stringify(result));
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get pre/post annotations working with a web application, but for some
I have a little sample application I was working on trying to get some
Hi im working on iphone application using monotouch im trying to get list of
I'm running CentOS 5, and am trying to get a django application working with
I'm trying to get tags working in my rails application and want to use
I'm trying to get Google Analytics working on an iPhone application without much luck.
I'm trying to get the MVCToolkit working with an ASP.NET MVC Beta application and
I am trying to get out of browser support working for my Silverlight application
I'm trying to get a jsonp callback working using jquery within a greasemonkey script.
I'm trying to get Facebook logins working on my app using Rails, Authlogic, and

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.