473,659 Members | 2,632 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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?


Nov 19 '05 #1
6 5572
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
HttpListenerCon text.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)
{
HttpListenerCon text ctx = l.GetContext();
string url = ctx.Request.Raw Url;
StreamWriter w = new
StreamWriter(ct x.Response.Outp utStream);
w.WriteLine("<h 2>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
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?


Nov 19 '05 #2
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
"Brock Allen" <ba****@NOSPAMd evelop.com> wrote in message
news:95******** **************@ msnews.microsof t.com...
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 HttpListenerCon text.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)
{
HttpListenerCon text ctx = l.GetContext();
string url = ctx.Request.Raw Url;
StreamWriter w = new
StreamWriter(ct x.Response.Outp utStream);
w.WriteLine("<h 2>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
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?


Nov 19 '05 #3
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.

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
"Brock Allen" <ba****@NOSPAMd evelop.com> wrote in message
news:95******** **************@ msnews.microsof t.com...
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
HttpListenerCon text.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)
{
HttpListenerCon text ctx = l.GetContext();
string url = ctx.Request.Raw Url;
StreamWriter w = new
StreamWriter(ct x.Response.Outp utStream);
w.WriteLine("<h 2>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
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?


Nov 19 '05 #4
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.
"Brock Allen" <ba****@NOSPAMd evelop.com> wrote in message
news:95******** **************@ msnews.microsof t.com...
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.

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
"Brock Allen" <ba****@NOSPAMd evelop.com> wrote in message
news:95******** **************@ msnews.microsof t.com...
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
HttpListenerCon text.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)
{
HttpListenerCon text ctx = l.GetContext();
string url = ctx.Request.Raw Url;
StreamWriter w = new
StreamWriter(ct x.Response.Outp utStream);
w.WriteLine("<h 2>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
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?


Nov 19 '05 #5
Just add a <httpHandlers > section to your web.config:

<configuratio n>
<system.web>
<httpHandlers >
<add path="YourURL.a spx" verb="POST" type="YourNames pace.YourClass, YourAssemblyWit houtTheDotDll"
/>
</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!

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.
"Brock Allen" <ba****@NOSPAMd evelop.com> wrote in message
news:95******** **************@ msnews.microsof t.com...
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.

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
"Brock Allen" <ba****@NOSPAMd evelop.com> wrote in message
news:95******** **************@ msnews.microsof t.com...
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

HttpListenerCon text.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)
{
HttpListenerCon text ctx = l.GetContext();
string url = ctx.Request.Raw Url;
StreamWriter w = new
StreamWriter(ct x.Response.Outp utStream);
w.WriteLine("<h 2>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
> 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?


Nov 19 '05 #6
its working!

"Brock Allen" <ba****@NOSPAMd evelop.com> wrote in message
news:95******** **************@ msnews.microsof t.com...
Just add a <httpHandlers > section to your web.config:

<configuratio n>
<system.web>
<httpHandlers >
<add path="YourURL.a spx" verb="POST" type="YourNames pace.YourClass, YourAssemblyWit houtTheDotDll" />
</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!

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.
"Brock Allen" <ba****@NOSPAMd evelop.com> wrote in message
news:95******** **************@ msnews.microsof t.com...
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.

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
"Brock Allen" <ba****@NOSPAMd evelop.com> wrote in message
news:95******** **************@ msnews.microsof t.com...
> 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

> HttpListenerCon text.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)
> {
> HttpListenerCon text ctx = l.GetContext();
> string url = ctx.Request.Raw Url;
> StreamWriter w = new
> StreamWriter(ct x.Response.Outp utStream);
> w.WriteLine("<h 2>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
>> 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?


Nov 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
9171
by: Cherrish Vaidiyan | last post by:
Hello all, A warm Xmas greetings to all. I have a small problem with starting up the database. Here my strategy. I have installed Oracle 9i R 2 on Red Hat 9. i created two database on this system. And the two datasbe is working perfectly. Now i needed another RH9 system to work on Oracle 9i. So I was guided to copy the oracle home folder and that the oracle will be up for work. I even got such a response from Google Group. I copied...
1
3732
by: Cherrish Vaidiyan | last post by:
sir, I have a small error in Listener configuration.I have two system with a database in each. I am using Red Hat 9 and Oracle 9i. so i shall anme the database and system. system 1 - node2 system 2 - node3 database - apple database - intel i have installed Oracle on 'node3' by copying the files and then creating a new database in it. Now i want to configure listener. I
3
694
by: Bill | last post by:
When vb6 Winsock.RemoteHost is set to "127.0.0.1", c# socket listener cannot hear connect request (my old vb6 winsock listener could hear it...). Why doesn't this work, and is there a work around I can make on the C# side to hear the connect request? -Bill (don't reply by e-mail, the address is a fake) ______________________________ Steps to reproduce: Start the C# Listener
1
1265
by: Ray Mitchell | last post by:
Hello, I've inherited the following code and am trying to get it to work. As I understand it's purpose, it creates a server, listens for a client to connect, does some work with the client, then loops back around and listens for the client to reconnect again in case it should become disconnected. If the client never disconnects it just sits there waiting forever.
1
1760
by: jm | last post by:
Easy probably, please read on. I know some of you have commented already about some of my socket question. I appreciate that. I have a Form1: static void Main() { Application.Run(new Form1()); clsListening.AsynchronousSocketListener.StartListening();
2
1866
by: iwdu15 | last post by:
hey, i was wondering if 1) anyone could tell me whats wrong with my code, i did a little fixing to the msdn version fo this, or 2) how to make a simple program that will connect and listen for connections async. if the user pushes the selected buttons. i just want a program that connects to another computer on the port and IP address selected and if the other computer is listening, then connect to it but this code doesnt work : Imports...
1
1499
by: klubbhead | last post by:
This part of my program needs to read from 4 parameter files and then displays them on the screen by clicking a different radio button. The program itself works, but my professor says that I have to improve the code in the DescriptionPanel 's listener because there are several lines of code that are identical and I should only have them once. Here is the code: import javax.swing.*; import java.awt.*; import java.awt.event.*; import...
5
38826
by: mivey4 | last post by:
Hi, First off, I am aware that this is a very heavily documented error and I have done my homework for throughly researching probable causes before deciding to post my problem here. At this point, I believe another set of eyes on the issue is merited. I am a MSSQL DBA and somewhat new to ORACLE; but I have read the administrators manual having a basic thorough level of knowledge (Tho' I am still learning) and understanding of how to...
0
2445
by: ryosaeba | last post by:
Hi to everybody...I'm new in thescripts forum... I've a big problem to make a simple Flash animated menù. I have a FLVPlayback component where I put inside a external FLV. TO this FLV I've mark 3 step by cuepoint. To every cuepoint I wish load an external .swf file (menù) into a empy MovieClip. Well the movie start...The listener find the first CP1 (cuepoint1) and the animation stopped (PAUSE), a menu1.swf is loaded into a empty...
0
8428
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8341
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8539
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7360
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6181
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4176
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1982
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1739
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.