HTTP and HTTPS Over My Socket

I need to be able to HTTP and SSL over my own socket (Socket class).  The big picture is that I'm writing a combined client and server for a protocol that sends XML messages via SOAP over HTTP and HTTPS with and without keep-alive and gzip.  I'd write a web service, but it looks like that won't give me sufficient control of the underlying socket.  With .NET 2.0, it looks like my life will be eased with SslStream, GZipStream, and XmlSerializer with XmlTypeMapping to help with SSL, GZip, and SOAP.  I think that only leaves HTTP for the non-SSL case.

1) Is there any .NET class that can make my life easier to do HTTP when I’m working with a Socket

2) Does the SslStream do the underlying HTTPS, or do I still need to write the HTTP headers and body to the SslStream

Thanks



Answer this question

HTTP and HTTPS Over My Socket

  • Ling Chen Wu

    1. You can stop listening and Start listening with HttpListener
    2. You can control the IP Address from where you are sending using the
    IPBindEndPointDelegate
    3. Using HTTP Listener you can just close the response and close the connection (I think)

    Even if you can't do everything I would use that framework for 90% of the cases and Write custom code only when you have to.  Why not use the code some one has already done for you

  • Fafa

    Thanks.  I really want to use those two classes if I can.

    1) I see I can Start() and Stop() an HttpListener.

    3) HttpListener and HttpWebRequest can Abort().

    Regarding 2), I didn't find IPBindEndPointDelegate at msdn2.microsoft.com or anywhere else on the web.  I also didn't see such a member at http://msdn2.microsoft.com/en-us/library/system.net.httpwebrequest_members.  Am I missing it

    Thanks



  • Ri

    It is BindIPEndPoint Delegate  
    take a look at
    http://blogs.msdn.com/malarch/archive/2005/09/13/466664.aspx





  • dlyford

    Thank you so much for your help.

  • samithad

    Thanks for the suggestions.

    Please correct me if I'm wrong, but I don't think I can use HTTPWebRequest or HTTPListener because I need to be able to do socket-level stuff like 1) not listen at times, 2) control the IP address I send from when running on a machine with multiple IPs, and 3) drop a connection after receiving a SOAP request without sending any response.

  • keyler

    In .net framework 2.0 we have
    1. a HTTPListener class that makes writing HTTP/HTTPS web server very easy.
    All you need to do is to handle the SOAP body yourself on the server.

    2. On the client you can use SSL Stream but SSLStream does not implement
    HTTP. You need to roll your own HTTP Client. On the other hand, there is really
    no need to do this. You can use the WebClient or HTTP Web Request to send and
    receive SSL.

    So my recommendation is to use HTTPWebRequest on the client and use HTTPListener on the server. You can set the Keep-Alive on the Client to false.

    Does the above recommendation work for you If not why not What sort of
    control you need on the underlying socket



  • HTTP and HTTPS Over My Socket