simple asynch web request question

  • Thread starter Thread starter mt404
  • Start date Start date
M

mt404

Hi everyone, I have what I think is a simple question concerning
making an asynchronous web request using the BeginGetResponse /
EndGetResponse methods of httpWebRequest.

My app needs to fire off a bunch (possibly thousands) of http requests
at once. Each request calls a java servlet which places a telephone
call. I need to examine the stream returned and do a simple SQL
update to log the status of the call. Unfortunately the info returned
by the servlet is pretty minimal and doesn't include any information
other than success, busy, no_answer, etc..

What I need to be able to do is identify which call each status
message relates to. However, I can't quite figure out how to do this
=( Is the state object what I should be paying attention to here? Is
there a way to make the phone number available to the callback
delegate that is receiving the response stream?

For instance to initate the request:

----------
string URI = "http://xxx.xxxx.com/connect-Phone?phone_number=555-555-5555";

HttpWebRequest req = (HttpWebRequest) WebRequest.Create(fullURI);

RequestState myRequestState = new RequestState(notificationId);

myRequestState.request = req;

IAsyncResult result = (IAsyncResult) req.BeginGetResponse(new
AsyncCallback(RespCallback),myRequestState);
------------

How can I get the 555-555-5555 as a variable to use in my SQL queries
held within RespCallback?


Many many thanks for any help anyone can offer!
 
MT404,

Yes, it's the state object you need to use.
See this articles from MSDN to understand how it is done.

--
Sorin Dolha [MCP, MCAD, MCSD]
Hi everyone, I have what I think is a simple question concerning
making an asynchronous web request using the BeginGetResponse /
EndGetResponse methods of httpWebRequest.

My app needs to fire off a bunch (possibly thousands) of http requests
at once. Each request calls a java servlet which places a telephone
call. I need to examine the stream returned and do a simple SQL
update to log the status of the call. Unfortunately the info returned
by the servlet is pretty minimal and doesn't include any information
other than success, busy, no_answer, etc..

What I need to be able to do is identify which call each status
message relates to. However, I can't quite figure out how to do this
=( Is the state object what I should be paying attention to here? Is
there a way to make the phone number available to the callback
delegate that is receiving the response stream?

For instance to initate the request:

----------
string URI = "http://xxx.xxxx.com/connect-Phone?phone_number=555-555-5555";

HttpWebRequest req = (HttpWebRequest) WebRequest.Create(fullURI);

RequestState myRequestState = new RequestState(notificationId);

myRequestState.request = req;

IAsyncResult result = (IAsyncResult) req.BeginGetResponse(new
AsyncCallback(RespCallback),myRequestState);
------------

How can I get the 555-555-5555 as a variable to use in my SQL queries
held within RespCallback?


Many many thanks for any help anyone can offer!
 
Sorin Dolha said:
MT404,

Yes, it's the state object you need to use.
See this articles from MSDN to understand how it is done.

Sorin,

I was able to get things working exaclty how I was hoping by creating
a class which I passed the data I needed to access in the callback
delegate to. I then used an instance of this class as the state
object for the async web request, and voila, I had everything working
exactly as I was hoping.

Thanks for confirming that I was barking up the right tree.

-Matt
 
Back
Top