Joe White’s Blog

Life, .NET, and Cats


Update on .NET Services with Indy

I was just glancing back through my blog, and noticed that I said Windows services were easy if you’re using Indy’s HTTP server component. (Reasonably true, it seems.) I also said that all you need to do is set the server component’s Active property to true in your service’s OnStart, and back to false in your OnStop. (Well, that’s what I thought at the time.)

Turns out the thing to do in OnStop is to call TIdHttpServer.Free. Free calls Dispose, and Dispose sets Active to false, so it all works out; but if you don’t call Free, if for example you call Dispose instead, then the service EXE and DLLs won’t actually unload from memory for a good fifteen or twenty seconds afterward. Don’t ask me why; in Reflector, it sure doesn’t look like Free is doing anything significant besides calling Dispose. It’s all pretty puzzling. It also plays havoc with your pre- and post-build events that stop and restart your service so you can recompile it; when you say stop, it says it’s stopped, but really it wants to think about it for a while longer first.

Another mysterious thing is that, if you call Free, it will apparently (we found out) immediately terminate any client connections. This even though Free calls Dispose, which sets Active to false, and the setter for the Active property (at least this is what the code looked like) waits for all client-servicing threads to terminate before it returns. So it shouldn’t, near as I can tell, be terminating connections when you Free it, but it is. This is what we get for working with beta software.

3 Responses to “Update on .NET Services with Indy”

  1. boydreaming Says:

    Do you know the indy httpd client componet how to post parameter with .aspx?

    follow is my code:

    var s:TMemoryStream;

    begin

    s:=TMemoryStream.Create;

    s.WriteString(’username=abc’);

    http.request.ContentType:=’application-x-www-form-urlencoded’;

    memo1.text:=http.post(’http://www.abc.com/test.aspx‘,s);

    end

    When it run,the test.aspx can’t get the ‘username’ value.

    Why?

    help me.

  2. Joe White Says:

    If you’re looking for an expert on Indy, you’re in the wrong place. :-P

    BTW, I was talking about the Indy server component. You’re using the Indy client component, which I haven’t used enough to count. And I’ve never used it for application-x-www-form-urlencoded. So… beats me.

    My first guess is that you have to form-encode the stream yourself, but that’s just a guess. Check to see if they have a demo. If not, you’re probably better asking on the Indy forums than here — we don’t even use the Indy HTTP components anymore.

  3. boydreaming Says:

    thank you for reply.:)

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


Joe White's Blog copyright © 2004-2008. Portions of the site layout use Yahoo! YUI Reset, Fonts, and Grids.
Proudly powered by WordPress. Entries (RSS) and Comments (RSS).