473,666 Members | 2,302 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Cur rent.Response.C ontentType = "applicatio n/xxx";
HttpContext.Cur rent.Response.B inaryWrite(arrR esult);
HttpContext.Cur rent.Response.F lush();
HttpContext.Cur rent.Response.E nd();
HttpContext.Cur rent.Response.C lose();
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 9105
I forgot to past some code....
HttpContext.Cur rent.Response.S tatusCode = 500;
throw new HttpException(5 00, "Error getting the file.\n\n" + e);

"Oscar" <xx@xx.dkwrot e in message
news:e5******** ******@TK2MSFTN GP05.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.Cur rent.Response.C ontentType = "applicatio n/xxx";
HttpContext.Cur rent.Response.B inaryWrite(arrR esult);
HttpContext.Cur rent.Response.F lush();
HttpContext.Cur rent.Response.E nd();
HttpContext.Cur rent.Response.C lose();
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.co m

"Oscar" <xx@xx.dkwrot e in message
news:%2******** **********@TK2M SFTNGP04.phx.gb l...
>I forgot to past some code....
HttpContext.Cur rent.Response.S tatusCode = 500;
throw new HttpException(5 00, "Error getting the file.\n\n" + e);

"Oscar" <xx@xx.dkwrot e in message
news:e5******** ******@TK2MSFTN GP05.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.Cu rrent.Response. ContentType = "applicatio n/xxx";
HttpContext.Cu rrent.Response. BinaryWrite(arr Result);
HttpContext.Cu rrent.Response. Flush();
HttpContext.Cu rrent.Response. End();
HttpContext.Cu rrent.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.Cur rent.Response.S tatusCode = 404;
throw new HttpException(4 04, "Error getting the file.\n\n" + e);

//Oscar
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c omwrote in
message news:50******** *************** ***********@mic rosoft.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.co m

"Oscar" <xx@xx.dkwrot e in message
news:%2******** **********@TK2M SFTNGP04.phx.gb l...
>>I forgot to past some code....
HttpContext.Cu rrent.Response. StatusCode = 500;
throw new HttpException(5 00, "Error getting the file.\n\n" + e);

"Oscar" <xx@xx.dkwrot e in message
news:e5******* *******@TK2MSFT NGP05.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.C urrent.Response .ContentType = "applicatio n/xxx";
HttpContext.C urrent.Response .BinaryWrite(ar rResult);
HttpContext.C urrent.Response .Flush();
HttpContext.C urrent.Response .End();
HttpContext.C urrent.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.co m

"Oscar" <xx@xx.dkwrot e in message
news:%2******** ********@TK2MSF TNGP04.phx.gbl. ..
Hi,

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

HttpContext.Cur rent.Response.S tatusCode = 404;
throw new HttpException(4 04, "Error getting the file.\n\n" + e);

//Oscar
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c omwrote
in message news:50******** *************** ***********@mic rosoft.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.co m

"Oscar" <xx@xx.dkwrot e in message
news:%2******* ***********@TK2 MSFTNGP04.phx.g bl...
>>>I forgot to past some code....
HttpContext.C urrent.Response .StatusCode = 500;
throw new HttpException(5 00, "Error getting the file.\n\n" + e);

"Oscar" <xx@xx.dkwrot e in message
news:e5****** ********@TK2MSF TNGP05.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.Respons e.ContentType = "applicatio n/xxx";
HttpContext. Current.Respons e.BinaryWrite(a rrResult);
HttpContext. Current.Respons e.Flush();
HttpContext. Current.Respons e.End();
HttpContext. Current.Respons e.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1566
by: guptatushar | last post by:
I have a Webservice which calls another component sitting on different machine Machine A Machine B Webservice ------------------->Component Due to network problem when webservice calls component it kinds of hung. I want to give a timeout to it and if within that timeout period nothing comes back just throw exception. Any one can give me an idea how to accomplish it.
2
2403
by: dan | last post by:
hi ng. i have a asp.net application which is client of an asp.net webservice. now i want to configure a custom error page (in case the sewrvice throws an exception) that provides the soapexception detail property as text. but when defined in web.config, the error page doesn't provide access to the thrown exception anymore. i think that i somehow have to enter the http pipeline to catch the error, read the data and transfer to a error...
11
3950
by: Andy | last post by:
Make the story short, I have a VB.NET client interface calling .NET webservice, written in VB.NET as well. I am trying to make the client as thin as possible so I let the webservice part to handle most of the things. Currently I have a class called "Product" sitting my webserivce like the following: Code:
7
5393
by: stephan querengaesser | last post by:
hi ng, i try to invoke a webservice-method with an filter-object, that contains value types. if i don´t want to filter the return value of the method, i have to pass a new instance of the filter-object without setting any properties. but the value type-properties can´t be null and the filter is set to 0 (int) or false (bool). therefore i did implement the propertySpecified-pattern like this:
0
1843
by: JeffL | last post by:
I am trying to either redirect or throw an error through a webservice that has been called through Microsoft webservice.htc element. What I want to be able to do is if a user which no longer autheticated (Time out has occured in forms authetication) that an error will return back to the caller saying a time out has occured. I have tried throwing an error in the global.asax Application_BeginRequest but the webservice.htc file always send...
3
12105
by: chris | last post by:
hello, I can't seem to make this work: VS2005 I have a simple program that uses a backgroundworker control to execute a long process (webservice call) if that webservice call fails, i want to raise an exception and display a messagebox. however no matter where i put the Try block to trap the error, it does not work.
1
238
by: jaydev | last post by:
Hello, I want to create a header and footer control which will be used in both the java and .net application. We are planning to create a webservice for this in C#. I am familiar in creating a webservice , but not sure how to create something compatible for java team (J2EE). Java team needs to output of webservice in XHTML, CSS and javascript format. Please throw some light on this. Thanks, Jay
2
2569
by: rn5a | last post by:
I have created the following WebService named NConnect.asmx using which I want an ASPX page to first authenticate a user & after successful user validation, the ASPX page should display a few TextBoxes for users to enter some data in those TextBoxes which will finally be inserted in a SQL Server 2005 DB table: <%@ WebService Language="VB" Class="NConnect" %> Imports System Imports System.Data
0
8356
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
8781
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8639
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7385
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
6192
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
5663
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4198
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...
0
4366
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2769
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.