Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / July 2005

Tip: Looking for answers? Try searching our database.

How to implemt a simple web listener in asp.net/vb.net

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jerome Cohen - 18 Jul 2005 20:14 GMT
I need to implement a simple application that listens for web requests on a
well-known URL, grab the request , which is an XML document, and send as
respnse an XML document.
each client sends a first request and I return failure or a session ID which
I store, and further requests should have the session ID.

isn't there a sim[ple way to do it? I keep reading about HTTP handlers.
isn't there a simpler way to implement it?
Brock Allen - 18 Jul 2005 20:40 GMT
If you don't need ASP.NET then you can host HTTP directly in an application
fairly easily using .NET 2.0 with http.sys (so Windows 2003 or XP SP2). Here's
a sample in C# that you should be able to morph to do XML. The trick is using
HttpListenerContext.Request and Response to do the heavy lifting for you

using System.IO;
using System.Net;

class Program
{
    static void Main(string[] args)
    {
        HttpListener l = new HttpListener();
        l.Prefixes.Add("http://localhost/HttpListenerApp/");
        l.Start();
        while (true)
        {
            HttpListenerContext ctx = l.GetContext();
            string url = ctx.Request.RawUrl;
            StreamWriter w = new
                          StreamWriter(ctx.Response.OutputStream);
            w.WriteLine("<h2>The URL was {0}</h2>", url);
            w.Close();
        }
    }
}

-Brock
DevelopMentor
http://staff.develop.com/ballen

> I need to implement a simple application that listens for web requests
> on a
[quoted text clipped - 6 lines]
> isn't there a sim[ple way to do it? I keep reading about HTTP
> handlers. isn't there a simpler way to implement it?
Jerome Cohen - 18 Jul 2005 20:36 GMT
thanks.

well, I do want to use ASP.NET/VB.NET. does it mean I have to use the HTTP
handlers method ?
my server is running WIN 2K

> If you don't need ASP.NET then you can host HTTP directly in an application
> fairly easily using .NET 2.0 with http.sys (so Windows 2003 or XP SP2). Here's
[quoted text clipped - 37 lines]
> > isn't there a sim[ple way to do it? I keep reading about HTTP
> > handlers. isn't there a simpler way to implement it?
Brock Allen - 18 Jul 2005 20:59 GMT
Ah, ok. I was just offering that as a non-IIS/ASP.NET approach as an idea.
So if you are using ASP.NET, then yes, implementing a IHttpHandler would
probabaly be your best bet. They're quite simple once you get started.

-Brock
DevelopMentor
http://staff.develop.com/ballen

> thanks.
>
[quoted text clipped - 56 lines]
>>> isn't there a sim[ple way to do it? I keep reading about HTTP
>>> handlers. isn't there a simpler way to implement it?
Jerome Cohen - 18 Jul 2005 21:00 GMT
thanks again!

assuming I have a page, "/dir1/mypage.aspx" that will implement the handler.
I understand I need to declare the public class that will implement the
handler
Public Class MyHandler

Implements IHttpHandler

and implement "IsReusable" and "ProcessRequest"

now, what exactly do I need to do on my web.configto make the handler
receive the requests to mypage.aspx? or does it does it have to be
machine.config? anything else I am missing?
all the examples I saw assume so much besides the basic HTTP handling its
hard to differenciate the "pure" HTTP handler.

> Ah, ok. I was just offering that as a non-IIS/ASP.NET approach as an idea.
> So if you are using ASP.NET, then yes, implementing a IHttpHandler would
[quoted text clipped - 64 lines]
> >>> isn't there a sim[ple way to do it? I keep reading about HTTP
> >>> handlers. isn't there a simpler way to implement it?
Brock Allen - 18 Jul 2005 21:22 GMT
Just add a <httpHandlers> section to your web.config:

<configuration>
<system.web>
<httpHandlers>
<add path="YourURL.aspx" verb="POST" type="YourNamespace.YourClass, YourAssemblyWithoutTheDotDll"
/>
</httpHandlers>
</system.web>
</configuration>

For the verb I'd use POST since you said the client would be passing up XML
in the body. You can just put verb="*" if they might also do a GET.

-Brock
DevelopMentor
http://staff.develop.com/ballen

> thanks again!
>
[quoted text clipped - 84 lines]
>>>>> isn't there a sim[ple way to do it? I keep reading about HTTP
>>>>> handlers. isn't there a simpler way to implement it?
Jerome Cohen - 18 Jul 2005 21:25 GMT
its working!

> Just add a <httpHandlers> section to your web.config:
>
[quoted text clipped - 102 lines]
> >>>>> isn't there a sim[ple way to do it? I keep reading about HTTP
> >>>>> handlers. isn't there a simpler way to implement it?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.