469,926 Members | 1,812 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,926 developers. It's quick & easy.

Webservice throw 404

Hi,

I got a webservie that supply users with binary files based on a parameter
id. The method is void and I stream the file by:

HttpContext.Current.Response.ContentType = "application/xxx";
HttpContext.Current.Response.BinaryWrite(arrResult );
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
HttpContext.Current.Response.Close();
return;

If the parameter id is invalid or if something goes wrong I would like to
throw either 404 och 500 exception. I been tring to do this with the
following code but I will allways recieve a 500. How can I control the
output exception.
May 15 '07 #1
4 8906
I forgot to past some code....
HttpContext.Current.Response.StatusCode = 500;
throw new HttpException(500, "Error getting the file.\n\n" + e);

"Oscar" <xx@xx.dkwrote in message
news:e5**************@TK2MSFTNGP05.phx.gbl...
Hi,

I got a webservie that supply users with binary files based on a parameter
id. The method is void and I stream the file by:

HttpContext.Current.Response.ContentType = "application/xxx";
HttpContext.Current.Response.BinaryWrite(arrResult );
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
HttpContext.Current.Response.Close();
return;

If the parameter id is invalid or if something goes wrong I would like to
throw either 404 och 500 exception. I been tring to do this with the
following code but I will allways recieve a 500. How can I control the
output exception.

May 15 '07 #2
Oscar,

Well, you are passing back a 500. In what case do you hope to send back
a 404? I don't see anything that indicates that you want to send back a 404
response.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Oscar" <xx@xx.dkwrote in message
news:%2******************@TK2MSFTNGP04.phx.gbl...
>I forgot to past some code....
HttpContext.Current.Response.StatusCode = 500;
throw new HttpException(500, "Error getting the file.\n\n" + e);

"Oscar" <xx@xx.dkwrote in message
news:e5**************@TK2MSFTNGP05.phx.gbl...
>Hi,

I got a webservie that supply users with binary files based on a
parameter id. The method is void and I stream the file by:

HttpContext.Current.Response.ContentType = "application/xxx";
HttpContext.Current.Response.BinaryWrite(arrResul t);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
HttpContext.Current.Response.Close();
return;

If the parameter id is invalid or if something goes wrong I would like to
throw either 404 och 500 exception. I been tring to do this with the
following code but I will allways recieve a 500. How can I control the
output exception.

May 15 '07 #3
Hi,

Sorry, I pasted the wrong code... it should of cource be:

HttpContext.Current.Response.StatusCode = 404;
throw new HttpException(404, "Error getting the file.\n\n" + e);

//Oscar
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote in
message news:50**********************************@microsof t.com...
Oscar,

Well, you are passing back a 500. In what case do you hope to send
back a 404? I don't see anything that indicates that you want to send
back a 404 response.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Oscar" <xx@xx.dkwrote in message
news:%2******************@TK2MSFTNGP04.phx.gbl...
>>I forgot to past some code....
HttpContext.Current.Response.StatusCode = 500;
throw new HttpException(500, "Error getting the file.\n\n" + e);

"Oscar" <xx@xx.dkwrote in message
news:e5**************@TK2MSFTNGP05.phx.gbl...
>>Hi,

I got a webservie that supply users with binary files based on a
parameter id. The method is void and I stream the file by:

HttpContext.Current.Response.ContentType = "application/xxx";
HttpContext.Current.Response.BinaryWrite(arrResu lt);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
HttpContext.Current.Response.Close();
return;

If the parameter id is invalid or if something goes wrong I would like
to throw either 404 och 500 exception. I been tring to do this with the
following code but I will allways recieve a 500. How can I control the
output exception.


May 15 '07 #4
Oscar,

You shouldn't have to set the StatusCode if you are throwing the
HttpException. Are you finding that just throwing the exception is not
returning a 404 response?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Oscar" <xx@xx.dkwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
Hi,

Sorry, I pasted the wrong code... it should of cource be:

HttpContext.Current.Response.StatusCode = 404;
throw new HttpException(404, "Error getting the file.\n\n" + e);

//Oscar
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote
in message news:50**********************************@microsof t.com...
>Oscar,

Well, you are passing back a 500. In what case do you hope to send
back a 404? I don't see anything that indicates that you want to send
back a 404 response.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Oscar" <xx@xx.dkwrote in message
news:%2******************@TK2MSFTNGP04.phx.gbl. ..
>>>I forgot to past some code....
HttpContext.Current.Response.StatusCode = 500;
throw new HttpException(500, "Error getting the file.\n\n" + e);

"Oscar" <xx@xx.dkwrote in message
news:e5**************@TK2MSFTNGP05.phx.gbl...
Hi,

I got a webservie that supply users with binary files based on a
parameter id. The method is void and I stream the file by:

HttpContext.Current.Response.ContentType = "application/xxx";
HttpContext.Current.Response.BinaryWrite(arrRes ult);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
HttpContext.Current.Response.Close();
return;

If the parameter id is invalid or if something goes wrong I would like
to throw either 404 och 500 exception. I been tring to do this with the
following code but I will allways recieve a 500. How can I control the
output exception.

May 15 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by stephan querengaesser | last post: by
1 post views Thread by jaydev | last post: by
2 posts views Thread by rn5a | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.