B
Bob
I have a web service using WSE 1.0SP DIME attachment to transfer files in
production. The synchronous call works great and pretty stable. I have
been trying to add the asyncrhonous calls. On the surface it works but then
I realized that when multiple async calls are made to the server in a loop,
some callbacks never happen (no exception either). Here's a piece of
simplified test code on the client side (Windows app) below. Everytime the
button click event is fired, anywhere from 1 to all the files may be
transferred. I'm suspecting some of the callbacks are colliding but don't
know how to check.
........................
private AsyncDime _svc; //AsyncDime is the WS proxy class.
//Windows Form button click event handler, this starts the async file
get process.
//This test trys to get 4 files from the server by giving the file
names.
private void btnGetFileAsync_Click(object sender, System.EventArgs e) {
string[] fns = new string[] {"BobTestFile.txt", "BobTestFile1.txt",
"BobTestFile2.txt", "BobTestFile3.txt"};
this._svc = new AsyncDime();
foreach (string fn in fns) {
AsyncCallback acb = new
AsyncCallback(this.RetrievalDoneCallback);
this._svc.BeginGetFile(fn, acb, this._svc);
}
}
//Handles the call back.
private void RetrievalDoneCallback(IAsyncResult returnValue) {
AsyncDime fileService = (AsyncDime)returnValue.AsyncState;
fileService.EndGetFile(returnValue);
string fileNameFrAttachment =
this.SaveAttachment(fileService.ResponseSoapContext.Attachments[0]);
}
//Save the attachement to a file
private string SaveAttachment(DimeAttachment da) {
int len;
byte[] chunk = new Byte[256];
System.IO.FileStream fs;
System.IO.Stream st;
string fileName = da.Id;
st = da.Stream;
fs = File.Open( @"c:\temp\" + fileName, FileMode.OpenOrCreate,
FileAccess.Write);
while ((len = st.Read(chunk, 0, chunk.Length)) > 0) {
fs.Write(chunk, 0, len);
}
st.Close();
fs.Close();
return fileName;
}
production. The synchronous call works great and pretty stable. I have
been trying to add the asyncrhonous calls. On the surface it works but then
I realized that when multiple async calls are made to the server in a loop,
some callbacks never happen (no exception either). Here's a piece of
simplified test code on the client side (Windows app) below. Everytime the
button click event is fired, anywhere from 1 to all the files may be
transferred. I'm suspecting some of the callbacks are colliding but don't
know how to check.
........................
private AsyncDime _svc; //AsyncDime is the WS proxy class.
//Windows Form button click event handler, this starts the async file
get process.
//This test trys to get 4 files from the server by giving the file
names.
private void btnGetFileAsync_Click(object sender, System.EventArgs e) {
string[] fns = new string[] {"BobTestFile.txt", "BobTestFile1.txt",
"BobTestFile2.txt", "BobTestFile3.txt"};
this._svc = new AsyncDime();
foreach (string fn in fns) {
AsyncCallback acb = new
AsyncCallback(this.RetrievalDoneCallback);
this._svc.BeginGetFile(fn, acb, this._svc);
}
}
//Handles the call back.
private void RetrievalDoneCallback(IAsyncResult returnValue) {
AsyncDime fileService = (AsyncDime)returnValue.AsyncState;
fileService.EndGetFile(returnValue);
string fileNameFrAttachment =
this.SaveAttachment(fileService.ResponseSoapContext.Attachments[0]);
}
//Save the attachement to a file
private string SaveAttachment(DimeAttachment da) {
int len;
byte[] chunk = new Byte[256];
System.IO.FileStream fs;
System.IO.Stream st;
string fileName = da.Id;
st = da.Stream;
fs = File.Open( @"c:\temp\" + fileName, FileMode.OpenOrCreate,
FileAccess.Write);
while ((len = st.Read(chunk, 0, chunk.Length)) > 0) {
fs.Write(chunk, 0, len);
}
st.Close();
fs.Close();
return fileName;
}