tags:

views:

54

answers:

1

The following C# WCF based REST service gives me some undesired headers that I'm not sure if I can remove them trough the API.

The interface:

[ServiceContract]
public interface IControlSystem
{
    [OperationContract]
    [WebGet]
    System.IO.Stream About();
}

The implementation:

public class ControlSystem : IControlSystem
{
    public System.IO.Stream About()
    {
        return new System.IO.MemoryStream(ASCIIEncoding.Default.GetBytes("Hello World"));
    }
}

Out of a raw socket connection it gives the following response:

HTTP/1.1 200 OK Server: ASP.NET Development Server/9.0.0.0 Date: Tue, 15 Jun 2010 13:12:51 GMT X-AspNet-Version: 2.0.50727 Cache-Control: private Content-Type: application/octet-stream Content-Length: 39 Connection: Close

Hello World

Question is, is it possible to get the server to not report anything other than the actual message? Need it in some calls so due to some small embedded device clients that will try to connect to the server and I would like to minimize the amount of parsing.

Thanks, B.

+1  A: 

What headers exactly are you trying to remove?

The X-Asp-Version header can be removed by setting the right options. There are other ways to remove other headers that might be useful as well when running under IIS (and not the asp.net dev server, which you wouldn't use in production anyway).

That said, you'll never be able to remove all the HTTP stuff; that's the core protocol design and it's required. If you don't want that, then, well, don't use HTTP at all and switch to a protocol more fitting to your needs (that might require implementing your own custom WCF transport channel, but it's certainly possible).

tomasr
Thanks, really appreciate it.
bmsantos
Ok, interesting enough is the fact that when running under IIS none of the headers is returned by default, witch happens to be exactly what I wanted.Also, I had a look in how to have a simple raw client connect to a custom binding but unfortunately there is no BindingElement that would allow me to have a non SOAP Message to go through. At best I could set a custom binding with TCP transport and Text for Message encoding. SOAP would still be used.
bmsantos
Just for documentation, here's a nice link on Binding Information: http://msdn.microsoft.com/en-us/magazine/cc163394.aspx#S4
bmsantos
If you're ok with HTTP but don't want SOAP, why not use WebHttpBinding instead?
tomasr