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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:45:09+00:00 2026-05-26T06:45:09+00:00

I’ve just spent a couple of hours debugging and looking through questions like POSTing

  • 0

I’ve just spent a couple of hours debugging and looking through questions like POSTing JSON to WCF REST Endpoint and Generic WCF JSON Deserialization, but currently I think my code and/or debugging is failing at quite a basic level…

I’ve set up a WCF service like:

[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, IncludeExceptionDetailInFaults = true)]
public class AutomationService : IAutomationService
{
    [WebInvoke(Method = "POST", UriTemplate = "getNextCommand")]
    public CommandBase GetNextCommand(int timeoutInMilliseconds)
    {
        // stuff
    }
}

where IAutomationService is:

[ServiceContract]
public interface IAutomationService
{
    [OperationContract]
    [ServiceKnownType("GetKnownTypes", typeof(KnownTypeProvider))]
    CommandBase GetNextCommand(int timeoutInMilliseconds);
}

and I’ve now got this service successfully setup with SOAP and JSON endpoints.

However… I can’t seem to work out how to call the service using variables passed in the ContentBody from Fiddler.

For example, I can call the service with a POST on the Uri – e.g.

   POST  http://localhost:8085/phoneAutomation/jsonAutomate/getNextCommand?timeoutInMilliseconds=10000

However, if I try to put the content in the body, then I get an exception. e.g.

POST http://localhost:8085/phoneAutomation/jsonAutomate/getNextCommand
Host: localhost:8085
Connection: keep-alive
Cache-Control: max-age=0
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.202 Safari/535.1
Accept: application/json,text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Cookie: Orchrd-=%7B%22Exp-N42-Settings%22%3A%22open%22%2C%22Exp-N42-New%22%3A%22open%22%7D
Content-Length: 31
Content-Type: application/json

{"timeoutInMilliseconds":10000}

fails with:

The server encountered an error processing the request. The exception
message is ‘There was an error deserializing the object of type
System.Int32. The value ” cannot be parsed as the type ‘Int32′.’. See
server logs for more details. The exception stack trace is:

at
System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator
reader, Boolean verifyObjectName, DataContractResolver
dataContractResolver) at
System.Runtime.Serialization.Json.DataContractJsonSerializer.ReadObject(XmlDictionaryReader
reader, Boolean verifyObjectName) at

…

Anyone got any ideas what I’m doing wrong (other than using WCF!) – I’m just not sure what shape the JSON {“timeoutInMilliseconds”:10000} is supposed to be.

  • 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-26T06:45:10+00:00Added an answer on May 26, 2026 at 6:45 am

    By default the “body style” of a WCF REST service is “Bare”, meaning that for operations with a single input, the value of the operation should go “as is” without any object wrapping it. That means in your case that this will work:

    POST http://localhost:8085/phoneAutomation/jsonAutomate/getNextCommand
    Host: localhost:8085
    Connection: keep-alive
    Cache-Control: max-age=0
    ...
    Content-Length: 5
    Content-Type: application/json
    
    10000
    

    One more thing, not directly related to your question: if you define a service contract in the interface, you should also add any “contract-related” attributes (such as WebInvoke) in the interface as well. That would make your code look like this:

    [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, IncludeExceptionDetailInFaults = true)]
    public class AutomationService : IAutomationService
    {
        public CommandBase GetNextCommand(int timeoutInMilliseconds)
        {
            // stuff
        }
    }
    
    [ServiceContract]
    public interface IAutomationService
    {
        [OperationContract]
        [ServiceKnownType("GetKnownTypes", typeof(KnownTypeProvider))]
        [WebInvoke(Method = "POST", UriTemplate = "getNextCommand")]
        CommandBase GetNextCommand(int timeoutInMilliseconds);
    }
    

    And another info: if you wanted to send the request the same way as you had originally ({"tiemoutInMilliseconds":10000}), you can set the BodyStyle property in the [WebInvoke] attribute to Wrapped (or WrappedRequest):

    [ServiceContract]
    public interface IAutomationService
    {
        [OperationContract]
        [ServiceKnownType("GetKnownTypes", typeof(KnownTypeProvider))]
        [WebInvoke(Method = "POST",
                   UriTemplate = "getNextCommand",
                   BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        CommandBase GetNextCommand(int timeoutInMilliseconds);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
I've got a string that has curly quotes in it. I'd like to replace
I would like to run a str_replace or preg_replace which looks for certain words
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.