472,977 Members | 1,889 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,977 software developers and data experts.

How to copy a file from web service to a remote client?

I have made a test: copy a text file to clinet side. But fails.
What I did is that create a web method in web services that read a text in
server side and return the text file as string. On the client side, the
method is called in a windows form client which stores the string and write
the string to a file. Though the file contains the original content but it
just a one-line string which is not the original copy.
Is there a general model which can copy the original file (any type) from
Web services server side to a remote client side? How to do that?

Thanks for any hint and help.

David

Nov 19 '05 #1
8 1683
I can handle text file correctly by spliting string by token. But how to
handle other types of files, for example, binary files.

David

"david" wrote:
I have made a test: copy a text file to clinet side. But fails.
What I did is that create a web method in web services that read a text in
server side and return the text file as string. On the client side, the
method is called in a windows form client which stores the string and write
the string to a file. Though the file contains the original content but it
just a one-line string which is not the original copy.
Is there a general model which can copy the original file (any type) from
Web services server side to a remote client side? How to do that?

Thanks for any hint and help.

David

Nov 19 '05 #2
Could you go into a bit more detail as to what you've tried?
Specifically, are you setting the content-type, clearing the cache, and
streaming the file across? If so, what errors are you seeing? Does
the code below look familiar? If so, you're at least on the right
track.

Response.ContentType = yourContentType; // ie.,
"application/vnd.ms-excel";
Response.AddHeader("content-disposition", "attachment; filename=" +
FileName);
Response.Write(yourFileContent);
Response.End();

Jason Kester
Expat Software Consulting Services
http://www.expatsoftware.com/

Nov 19 '05 #3
I do not go this way (HTTP request/response). I created a XML web services
class, say A, on werver side which contains Webmethods that will be called by
the proxy at lient side. Those webmethods read files in server side and
return the file content as a string. In client side, I create a windows form
application, B, which generates a proxy A' of A and uses A' to call those
Webmethods and gets the string of the file content. So I could virtually copy
a file from Server side to the Client side.

Is there a general model to it for any type of file?

David

"jasonkester" wrote:
Could you go into a bit more detail as to what you've tried?
Specifically, are you setting the content-type, clearing the cache, and
streaming the file across? If so, what errors are you seeing? Does
the code below look familiar? If so, you're at least on the right
track.

Response.ContentType = yourContentType; // ie.,
"application/vnd.ms-excel";
Response.AddHeader("content-disposition", "attachment; filename=" +
FileName);
Response.Write(yourFileContent);
Response.End();

Jason Kester
Expat Software Consulting Services
http://www.expatsoftware.com/

Nov 19 '05 #4
No.

If you're using .NET's built-in SOAP functionality, you're going to be
dealing in XML files. This pretty much limits your returned content to
plain text. You'll probably run into much more pain trying to work
around all the issues you'll run into than you would dealing with a
simple HttpRequest to an .aspx.

Jason Kester
Expat Software Consulting Services
http://www.expatsoftware.com/

Nov 19 '05 #5
But I want to use windows application in client side as thick client (not web
client). The reason is that we have some larger windows based applications
which read and process image files locally (not common use on web such as
jpg, gif, ...). So I need to build a database which indicates the files
location and get the files from remote server. What can I do? use COM/DCOM,
winsocket, or embedded an application into HTML web browser? Based on your
experience and knowledge, what is the better way to do it?

I know how to embedded Java applet into HTML. How about MS windows
application?

Thank you for your help.

"jasonkester" wrote:
No.

If you're using .NET's built-in SOAP functionality, you're going to be
dealing in XML files. This pretty much limits your returned content to
plain text. You'll probably run into much more pain trying to work
around all the issues you'll run into than you would dealing with a
simple HttpRequest to an .aspx.

Jason Kester
Expat Software Consulting Services
http://www.expatsoftware.com/

Nov 19 '05 #6
When I read XML Web Services book, it states that we can use this kind of
technology to transfer Text file and binary files, but I can not find any
example.

By the way, when they talk about binary serialized od Web Services, what
does it exactly mean?

David

"david" wrote:
But I want to use windows application in client side as thick client (not web
client). The reason is that we have some larger windows based applications
which read and process image files locally (not common use on web such as
jpg, gif, ...). So I need to build a database which indicates the files
location and get the files from remote server. What can I do? use COM/DCOM,
winsocket, or embedded an application into HTML web browser? Based on your
experience and knowledge, what is the better way to do it?

I know how to embedded Java applet into HTML. How about MS windows
application?

Thank you for your help.

"jasonkester" wrote:
No.

If you're using .NET's built-in SOAP functionality, you're going to be
dealing in XML files. This pretty much limits your returned content to
plain text. You'll probably run into much more pain trying to work
around all the issues you'll run into than you would dealing with a
simple HttpRequest to an .aspx.

Jason Kester
Expat Software Consulting Services
http://www.expatsoftware.com/

Nov 19 '05 #7
david wrote:
But I want to use windows application in client side as thick client (not web
client).


Right. That was assumed. Remember, the SOAP web service you are
trying to build is doing a HTTP post behind the scenes. Its
abstraction appears to be hindering you in this case rather than
helping. Thus, you are probably better off deconstructing the process.

So again, try looking at the HttpRequest object from your winform code.
Build a simple .aspx page to act as your web service and document
server. Your client HttpRequest will give you a HttpResponse that will
contain document information, a filename, and a Stream that you can use
to store the document locally. Here is a bit of code that might get
you pointed in the right direction:
HttpWebRequest webRequest = WebRequest.Create(url) as HttpWebRequest;
webRequest.Method = "GET";

HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse();
BinaryReader responseReader = new
BinaryReader(response.GetResponseStream());

if (response.ContentLength > -1)
{
byte[] buffer = new byte[response.ContentLength];

FileStream fs = new FileStream(fileName, FileMode.Create);
BinaryWriter writer = new BinaryWriter(fs);

long pos=0;
int count=1;
while (count > 0 && pos < response.ContentLength)
{
count = responseReader.Read(buffer, (int)pos,
(int)(response.ContentLength - pos));
writer.Write( buffer, (int)pos, count);
pos += count;
}

writer.Close();
fs.Close();
}

Jason Kester
Expat Software Consulting Services
http://www.expatsoftware.com/

Nov 19 '05 #8
Thank you, Jason. I will try it.

Your whole sample code is for windows client, is that right?
And url should point to the file location and name at the web server side.

David
"jasonkester" wrote:
david wrote:
But I want to use windows application in client side as thick client (not web
client).


Right. That was assumed. Remember, the SOAP web service you are
trying to build is doing a HTTP post behind the scenes. Its
abstraction appears to be hindering you in this case rather than
helping. Thus, you are probably better off deconstructing the process.

So again, try looking at the HttpRequest object from your winform code.
Build a simple .aspx page to act as your web service and document
server. Your client HttpRequest will give you a HttpResponse that will
contain document information, a filename, and a Stream that you can use
to store the document locally. Here is a bit of code that might get
you pointed in the right direction:
HttpWebRequest webRequest = WebRequest.Create(url) as HttpWebRequest;
webRequest.Method = "GET";

HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse();
BinaryReader responseReader = new
BinaryReader(response.GetResponseStream());

if (response.ContentLength > -1)
{
byte[] buffer = new byte[response.ContentLength];

FileStream fs = new FileStream(fileName, FileMode.Create);
BinaryWriter writer = new BinaryWriter(fs);

long pos=0;
int count=1;
while (count > 0 && pos < response.ContentLength)
{
count = responseReader.Read(buffer, (int)pos,
(int)(response.ContentLength - pos));
writer.Write( buffer, (int)pos, count);
pos += count;
}

writer.Close();
fs.Close();
}

Jason Kester
Expat Software Consulting Services
http://www.expatsoftware.com/

Nov 19 '05 #9

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

Similar topics

1
by: Paul Fi | last post by:
I have this problem with .NET remoting: my remote class is called RemoteHandler which implements an interface called IEazyRemoting which has only one method to be implemented which is my server...
2
by: Paul | last post by:
Dear All, I want to use web form to upload my file and copy the file to another machine. I can upload the file, but when I copy the file(file.CopyTo(".....", true)) to another machine(map...
3
by: Steve Lutz | last post by:
Hi All, I have a Windows Service that runs well. The service hosts a remote object. The purpose of the object is so that I can "peak" into the service to see what it's doing. I wrote a small...
1
by: POnfri | last post by:
Hi, I have a problem in a peace of code were i'm doing a file copy using File.Copy. The Source is local and the target is a remote machine. Example: File.Copy(C:\temp\hi.txt,...
2
by: Stu | last post by:
Using IIs 6.0 on a Server 2003 box, and using ASP.NET I'm trying to do the following code snippit... Dim NewName As String = "\\network_share_path\edit_me.ppt" Dim PubName As String =...
6
by: Pat Carden | last post by:
Hi, We need to allow webusers to upload a file on our website (on Server3, all servers run Server 2003, remotely hosted) and eventually save it on our SBS Server (Server2) which is not exposed...
3
by: Fredric Ragnar | last post by:
Hi, I am making a prototype system with Remoting in the bottom of the system. An XML Web Service is using the remote object on an IIS to present data. I am using a TcpChannel for communicating...
3
by: Crash | last post by:
VS 2003 ..NET 1.x Windows 2000 SP4 Hi all, We recently migrated a data center containing several database and ASP web service servers. We have a Windows Forms application that runs on 200+...
14
by: Peter | last post by:
..NET 3.5 I have a Windows Service application and it does remoting, but when a client incounters an error the client get the following error message "Server encountered an internal error....
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.