473,467 Members | 1,575 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

steam url out to a client

Hi

I need to load an url which should return an pdf/doc file or and html
page if file not found I then need to return this file to the
request(client) as ether as a download using
Response.AppendHeader("Content-Disposition", " attachment; filename=" +
fileName); or inline

Effectly I need to make a web page work as a proxy

This is for a document system where some of the file are in a local
store and some of the file are on remote webservice I need to hide the
source location from the users so all they know is the the url of a
document is fietch.aspx?docid=1234 so i can control access etc.

the local file is easy i am using
"Response.TransmitFile(pathAndFileName);" But Ican't find the code to
stream in and response an remote URL

Any pointer / code will help

Paul

Dec 8 '06 #1
6 2515
If you expect the pages to be small, you should be able to just use
something like WebClient.DownloadData, and then just write the array
directly to the response stream. For larger content, you may have to get the
(remote) response-stream and pump the data in chunks to the (local)
response-stream.

You may also wish to consider a simpler model, such as a handler (ashx)
rather than a page (aspx).

Marc
Dec 8 '06 #2
Hi Paul,

If it's truly a "Web Service" from which you are downloading the file then
you can simply write it directly to Response.OutputStream after it's
retrieved.

--
Dave Sexton

<pb*****@gmail.comwrote in message
news:11*********************@j44g2000cwa.googlegro ups.com...
Hi

I need to load an url which should return an pdf/doc file or and html
page if file not found I then need to return this file to the
request(client) as ether as a download using
Response.AppendHeader("Content-Disposition", " attachment; filename=" +
fileName); or inline

Effectly I need to make a web page work as a proxy

This is for a document system where some of the file are in a local
store and some of the file are on remote webservice I need to hide the
source location from the users so all they know is the the url of a
document is fietch.aspx?docid=1234 so i can control access etc.

the local file is easy i am using
"Response.TransmitFile(pathAndFileName);" But Ican't find the code to
stream in and response an remote URL

Any pointer / code will help

Paul

Dec 8 '06 #3
What I an expecting is a pdf/doc file if the file is found else I will
get an HTML error page

I do wish to be able to forse the file into dowmload mode ie. havw to
links per file download - view

some of these file will be big so I do need to be carefull not to
overload the server etc.

So It might be safer to write to the file system
On Dec 8, 12:42 pm, "Dave Sexton" <dave@jwa[remove.this]online.com>
wrote:
Hi Paul,

If it's truly a "Web Service" from which you are downloading the file then
you can simply write it directly to Response.OutputStream after it's
retrieved.

--
Dave Sexton

<pbea...@gmail.comwrote in messagenews:11*********************@j44g2000cwa.go oglegroups.com...
Hi
I need to load an url which should return an pdf/doc file or and html
page if file not found I then need to return this file to the
request(client) as ether as a download using
Response.AppendHeader("Content-Disposition", " attachment; filename=" +
fileName); or inline
Effectly I need to make a web page work as a proxy
This is for a document system where some of the file are in a local
store and some of the file are on remote webservice I need to hide the
source location from the users so all they know is the the url of a
document is fietch.aspx?docid=1234 so i can control access etc.
the local file is easy i am using
"Response.TransmitFile(pathAndFileName);" But Ican't find the code to
stream in and response an remote URL
Any pointer / code will help
Paul
Dec 11 '06 #4
Hi Paul,
What I an expecting is a pdf/doc file if the file is found else I will
get an HTML error page
It doesn't sound to me like you're using a Web Service at all then :)

It sounds to me like you're simply making an HTTP request for a document
directly to a web server, in which case Marc's solutions are good ones.
I do wish to be able to forse the file into dowmload mode ie. havw to
links per file download - view
It's not clear to me what you want here. Do you mean asynchronous
downloads?
some of these file will be big so I do need to be carefull not to
overload the server etc.

So It might be safer to write to the file system
Well, if you're going to be downloading the complete files into memory
anyway then writing them to disc will actually be more of a burden on the
server. Marc's suggestion about downloading large files in chunks seems
like it might be appropriate for your situation. Just write each chunk to
the Response.OutputStream one at a time. The size of the chunks should
depend on the available resources of the system that is hosting your
application, although you'll probably be able to get away with hard-coding
some size like 0x20000.

--
Dave Sexton
Dec 11 '06 #5
Hi

I am all ready fetching files from the local file system using

Response.TransmitFile(filePath);

and I eaither set this to make the save as dailog appear
Response.AppendHeader("Content-Disposition", " attachment; filename=" +
fileName);

or this to make the brouser to try and load it
Response.AppendHeader("Content-Disposition", " inline; filename=" +
fileName);

My problems come when the file I want to return is not the local file
but been returned by a remote service

I was just have problems get the streaming to work and have been able
to find any examples of this been done

will WebClient.DownloadData work with DPF/DOC files
Thanks for you help Paul
I do like the idea of change this into a ashx page when it is all
working
On Dec 11, 2:21 pm, "Dave Sexton" <dave@jwa[remove.this]online.com>
wrote:
Hi Paul,
What I an expecting is a pdf/doc file if the file is found else I will
get an HTML error pageIt doesn't sound to me like you're using a Web Service at all then :)

It sounds to me like you're simply making an HTTP request for a document
directly to a web server, in which case Marc's solutions are good ones.
I do wish to be able to forse the file into dowmload mode ie. havw to
links per file download - viewIt's not clear to me what you want here. Do you mean asynchronous
downloads?
some of these file will be big so I do need to be carefull not to
overload the server etc.
So It might be safer to write to the file systemWell, if you're going to be downloading the complete files into memory
anyway then writing them to disc will actually be more of a burden on the
server. Marc's suggestion about downloading large files in chunks seems
like it might be appropriate for your situation. Just write each chunk to
the Response.OutputStream one at a time. The size of the chunks should
depend on the available resources of the system that is hosting your
application, although you'll probably be able to get away with hard-coding
some size like 0x20000.

--
Dave Sexton
Dec 12 '06 #6
It makes no difference what the underlying remote response is; it could
be doc, pdf, txt, etc... no different.

Essentially, the following should work, which forwards all headers and
content, without ever holding the entire remote page in memory:

public void ProcessRequest (HttpContext context) {
HttpResponse localResponse = context.Response;
using (WebClient wc = new WebClient())
using (Stream remoteResponseStream =
wc.OpenRead(@"http://groups.google.com"))
using (Stream localResponseStream = localResponse.OutputStream)
{
localResponse.Clear();
WebHeaderCollection remoteHeaders = wc.ResponseHeaders;
foreach (string key in remoteHeaders.AllKeys) {
string header = remoteHeaders.Get(key);
System.Diagnostics.Debug.WriteLine(header, key);
localResponse.AddHeader(key, header);
}
const int BUFFER_SIZE = 2048;
int bytesRead;
long totalBytes = 0;
byte[] buffer = new byte[BUFFER_SIZE];
while((bytesRead = remoteResponseStream.Read(buffer, 0,
BUFFER_SIZE)) 0) {
localResponseStream.Write(buffer, 0, bytesRead);
totalBytes += bytesRead;
}
System.Diagnostics.Debug.WriteLine(totalBytes,
"*written:");
}
}

Dec 12 '06 #7

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

Similar topics

15
by: Michael Rybak | last post by:
hi, everyone. I'm writing a 2-players game that should support network mode. I'm now testing it on 1 PC since I don't have 2. I directly use sockets, and both client and server do...
18
by: cjl | last post by:
Hey all: I know that it is silly in the age of Google to 'lose' something on the internet, but I recently checked out a project that had implemented a database with a subset of SQL in pure...
6
by: Ken Allen | last post by:
I am relatively new to .Net and C#, but I hav ebeen programing in other languages and done some COM work for a number of years. I am attempting to understand how to map an older program...
4
by: rs | last post by:
how I the client tell the server that the socket is closed? or this there an even that informs the server that the clients socket is close? Oh, I am using vb.net 2003 Thanks
2
by: J Huntley Palmer | last post by:
I am having a horrific time integrating uw-imap's c-client for imap support in php. The problem is a whole bunch of "Text relocation remains referenced against symbol" errors during linking....
0
by: =?Utf-8?B?U3Vl?= | last post by:
I need your help. I am a medical transcriptionist trying to start a new job. I have dowloaded the company's software (Chart Net) and when I try to open the voice files I get this ACM steam open...
2
by: nsaffary | last post by:
hi I hava a client/server program that run correctly when i run it in one computer(local) but when I run client on a one computer and run server run on another, connection does not stablish.(I set...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
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...
1
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.