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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:22:02+00:00 2026-06-15T02:22:02+00:00

So, I have been messing around with webservices for a while now, and I

  • 0

So, I have been messing around with webservices for a while now, and I keep getting back to some basics, that I never seem to get right.

Question 1:

When using a WebServiceHost in .NET/C#, you can define a method/endpoint as using GET/POST/etc. Setting up a GET-method is easy and it works pretty much directly, and its easy to understand how it works. For example:

[OperationContract]
[WebInvoke(Method = "GET", UriTemplate = "/PutMessage/{jsonString}", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]
string PutMessage(string jsonString);

If I call http:///MyWebService/PutMessage/{MyJsonString} I get passed on the the method, and all is well (more or less).

But then what does it mean when I define this as a POST instead?

[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "/PutMessage/{jsonString}", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]
string PutMessage(string jsonString);

What does the UriTemplate do here? If I do a POST, I expect the data to be contained not in the URI, but in the “data section” of the post. But do I define the variable name in the data section? How does the WebServiceHost/.NET know that what is contained in the “data section” of the post is to be put into the variable jsonString? How do I post the data from the client side (not C#, let’s say JQuery instead) so that it is interpreted correctly on the serer side?

(And how does the WebMessageFormat affet things? I have read everywhere about this (MSDN, Stackoverflow etc) but haven’t found a clear and good answer.)

Question 2:

In my attempts to understand this, I thought I’d make a very simple POST-method, like this:

[OperationContract]
[WebInvoke]
string PutJSONRequest(string pc);

I then try call this method using Fiddler, but that does not work at all. I just get a 400 error back, saying “HTTP/1.1 400 Bad Request”. I have a breakpoint on the very first line in the code of the method, and the method itself contains nothing:

public string PutJSONRequest(string pc)
{
    return null;
}

Again, how does .NET know that what I POSTed using Fiddler should be contained in the “string pc”? How does it interpret it as a string, and what type of string (UT8, ASCII etc)?

This is the RAW HTTP request, sent from Fiddler:

POST http://<myip>:8093/AlfaCustomerApp/PutJSONRequest HTTP/1.1
User-Agent: Fiddler
Host: <myip>:8093
Content-Length: 3
Content-type: application/x-www-form-urlencoded; charset=UTF-8

asd

and it doesnt matter what type of Content-type I use, as far as I can see.

The response is a standard-thing, that I am not in control of myself:

HTTP/1.1 400 Bad Request
Content-Length: 1165
Content-Type: text/html
Server: Microsoft-HTTPAPI/2.0
Date: Mon, 15 Oct 2012 15:45:02 GMT

[then HTML code]

Any help would be appreciated. Thanks.

  • 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-15T02:22:03+00:00Added an answer on June 15, 2026 at 2:22 am

    I found out the answer. This is how to define a method, that can take the raw data sent in a HTTP POST:

    [OperationContract]
    [WebInvoke(BodyStyle=WebMessageBodyStyle.Bare)]
    Stream PutMessage(Stream data);
    

    and the implementation is like this:

    public Stream PutMessage(Stream data)
    {
        byte[] buffer = new byte[65535];
    
        int bytesRead, totalBytes = 0;
        do
        {
            bytesRead = data.Read(buffer, 0, 65535);
            totalBytes += bytesRead;
        }
        while (bytesRead > 0);
    
        // Then you could interpret it as a String for example:
        string jsonString = Encoding.UTF8.GetString(buffer, 0, totalBytes);
        // yada yada
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been messing around with Cocos2d for a while but decided that, due
I have been messing around with writing some stored procedures in .NET code with
I have been messing around with OpenGL lately, and I noticed that the windows
i am haveing some problems with JSON and arrays. I have been messing around
I've been messing around a bit with a Facebook application for a while now,
I have been messing around with recursion today. Often a programming technique that is
I have been messing around with web.py lately and wanted to grab some stuff
I've been messing around with different forms and tables, now I need something that
I have been messing around with asp.net for awhile now and always have issues
I have been messing around with webmin and creating vhosts, now normally I would

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.