473,386 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

WebService - Multiple Access

I have developed a webservice which is used for LIVEUPDATES for win
application. Method is used for donwloading new files from server to Clients
PC. It is working OK when one user is accessing method, but stuck when many
users try to access method.

Please help what is wrong in coding

Hemant

Nov 23 '05 #1
2 1682
hi hemant,
do you close the file stream? it sounds like the file might be locked. if
the web method is getting stuck, it may be throwing an exception that is not
being handled. are you invoking the method on another thread?

this is code i use to send a file to a win-app from a web service. it sends
the file as a byte[] to the client. notice that i have a 'finally' clause
that always closes the file.

[WebMethod]
public byte[] DownloadFile(string filename)
{
// check that dir exists
DirectoryInfo dirInfo = new DirectoryInfo(Server.MapPath("bin/exec"));
if(!dirInfo.Exists)
throw new Exception("Unable to retrieve server file information.\n Path
not found for bin/exec");

string path = dirInfo.FullName + "\\" + filename;
// check that requested file exists
FileInfo f = new FileInfo(path);
if(!f.Exists)
throw new Exception("Unable to retrieve server file information.\n File
not found for " + path);

// open the file to stream as a byte[]
FileStream stream = File.OpenRead(path);
if (stream != null && stream.Length > 0)
{
try
{
byte[] bytes = new byte[stream.Length];
stream.Read(bytes, 0, bytes.Length);
return bytes;
}
catch(Exception ex)
{
throw new Exception("Failed to read from file " + filename + ".\n" +
ex.Message);
}
finally
{
stream.Close();
}
}
else
throw new Exception("Could not read file into byte array.");
}

hope this helps
tim

--------------------------
blog: http://tim.mackey.ie

"Hemant Athavale" <He************@discussions.microsoft.com> wrote in
message news:39**********************************@microsof t.com...
I have developed a webservice which is used for LIVEUPDATES for win
application. Method is used for donwloading new files from server to
Clients
PC. It is working OK when one user is accessing method, but stuck when
many
users try to access method.

Please help what is wrong in coding

Hemant

Nov 23 '05 #2
Hi! Mac

Thanks for reply and time...

I closed the filestream but may be I forgot to give share access to file.

I will check and if need more help will come back.

Thanks and regards

Hemant

"Tim_Mac" wrote:
hi hemant,
do you close the file stream? it sounds like the file might be locked. if
the web method is getting stuck, it may be throwing an exception that is not
being handled. are you invoking the method on another thread?

this is code i use to send a file to a win-app from a web service. it sends
the file as a byte[] to the client. notice that i have a 'finally' clause
that always closes the file.

[WebMethod]
public byte[] DownloadFile(string filename)
{
// check that dir exists
DirectoryInfo dirInfo = new DirectoryInfo(Server.MapPath("bin/exec"));
if(!dirInfo.Exists)
throw new Exception("Unable to retrieve server file information.\n Path
not found for bin/exec");

string path = dirInfo.FullName + "\\" + filename;
// check that requested file exists
FileInfo f = new FileInfo(path);
if(!f.Exists)
throw new Exception("Unable to retrieve server file information.\n File
not found for " + path);

// open the file to stream as a byte[]
FileStream stream = File.OpenRead(path);
if (stream != null && stream.Length > 0)
{
try
{
byte[] bytes = new byte[stream.Length];
stream.Read(bytes, 0, bytes.Length);
return bytes;
}
catch(Exception ex)
{
throw new Exception("Failed to read from file " + filename + ".\n" +
ex.Message);
}
finally
{
stream.Close();
}
}
else
throw new Exception("Could not read file into byte array.");
}

hope this helps
tim

--------------------------
blog: http://tim.mackey.ie

"Hemant Athavale" <He************@discussions.microsoft.com> wrote in
message news:39**********************************@microsof t.com...
I have developed a webservice which is used for LIVEUPDATES for win
application. Method is used for donwloading new files from server to
Clients
PC. It is working OK when one user is accessing method, but stuck when
many
users try to access method.

Please help what is wrong in coding

Hemant


Nov 23 '05 #3

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

Similar topics

6
by: Davie | last post by:
I want to authorise a user of a web service by using the AuthHeaderValue for some reason I keep getting a null reference exception when I try to run the following code: It seems to work fine on a...
0
by: Jason | last post by:
I have a customer who needs multiple people from multiple locations to view ~12 reports. Naturally, I thought a web page hosting these reports would be best however I'm not sure if I should make...
5
by: | last post by:
Hi, How long do webservice objects live for? In particular, if i have static variables filled with data from a static constructor in a webservice, how long will that data persist? thxs
2
by: twotoed | last post by:
Hi, Does anyone have any experience with/suggestions for using a webservice for product licensing? What I have in mind is something like where the client app sends their product key to the...
1
by: Ezz | last post by:
I have an interesting problem...and its one of those where I know what I want but don't know how to ask it =) I have an eCommerce application that uses Paypal for its payment gateway. It is an...
1
by: Thom Little | last post by:
I have a simple web service that requires no input and returns a character string. I created the service and FTPd it to a remote server. The .dll to the .bin directory and the single .asmx file...
6
by: Steve Ricketts | last post by:
I have a webservice written in VB.net that opens a connection to SQL Server 2000 with a connection string. The connection remains open for the life of the web service so the ADODB.connection is...
4
by: Jonathan | last post by:
I have a SQL stored procedure for adding a new record in a transactions table. It also has two return values: CounterID and IDKey. I want to create a webservice that accepts the 10 input...
7
by: Amirallia | last post by:
Hi, I consume my webservice with the IE browser and all is ok when I call it with one browser. But when I call it a the same time with two browsers, the IE page tells me that the apllication...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...

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.