I switched to WCF b/c I've heard it's much faster then asmx. Also the WCF is configured to use MTOM while the asmx service is not. My WFC service call takes about 1 min 20 seconds to complete on a file download (streaming it in chunks) and my old asmx service takes 1 min 7 seconds to just return one massive response of embedded byte data. I'm downloading a 1.5 MB file 5 times with both calls.
static void Main(string[] args)
{
ServiceReference3.TestCloudWebSvcClient client = new ServiceReference3.TestCloudWebSvcClient();
client.Open();
Console.WriteLine("Getting file blocks...");
System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch();
stopWatch.Start();
for (int i = 0; i < 5; i++)
{
byte[] fileChunkData = null;
int offset = 0;
int totalBytes = 0;
bool moreDataAvail = true;
string filePath = string.Format(@"C:\Users\\Downloads\icuin44({0}).dll", i.ToString());
if (File.Exists(filePath))
File.Delete(filePath);
using (FileStream fs = new FileStream(filePath, FileMode.Append, FileAccess.Write))
{
while (moreDataAvail == true)
{
Console.WriteLine("More data avail is true for iteration " + i.ToString() + ", executing command...");
string errorMsg = client.DownloadLargeFile(128000, "", "icuin44.dll", 5, offset, "", "", out moreDataAvail, out fileChunkData);
Console.WriteLine("Command executed. Error Msg: {0} | Block length: {1}", errorMsg, (fileChunkData != null) ? fileChunkData.Length.ToString() : "null");
// Now that we have the new byte data (assuming the call worked), lets write it to the stream.
if (fileChunkData != null)
{
fs.Write(fileChunkData, 0, fileChunkData.Length);
offset += 128000;
totalBytes += fileChunkData.Length;
}
Console.WriteLine("Wrote {0} bytes for a total of {1} bytes to file stream...", fileChunkData.Length, totalBytes);
}
fs.Close();
fs.Dispose();
}
}
stopWatch.Stop();
Console.WriteLine("Time elapsed while running functions: {0}", stopWatch.Elapsed.ToString());
stopWatch.Reset();
client.Close();
Console.WriteLine("Closed client successfully");
Console.WriteLine("Attempting to download file via legacy service...");
stopWatch.Start();
ServiceReference4.TestWebSvcSoapClient client2 = new ServiceReference4.TestCloudWebSvcSoapClient();
ServiceReference4.DownloadFilesResponse res = client2.GetDirectSvrFiles("", "", new ServiceReference4.FileSvcDef[] { new ServiceReference4.FileSvcDef() { DirPath = "", FileLastSyncDate = new DateTime(2012, 5, 9), FileName = "icuin45.dll" },
new ServiceReference4.FileSvcDef() { DirPath = "", FileLastSyncDate = new DateTime(2012, 5, 9), FileName = "icuin45.dll" }, new ServiceReference4.FileSvcDef() { DirPath = "", FileLastSyncDate = new DateTime(2012, 5, 9), FileName = "icuin45.dll" },
new ServiceReference4.FileSvcDef() { DirPath = "", FileLastSyncDate = new DateTime(2012, 5, 9), FileName = "icuin45.dll" }, new ServiceReference4.FileSvcDef() { DirPath = "", FileLastSyncDate = new DateTime(2012, 5, 9), FileName = "icuin45.dll" }});
if(res.FileBinaryList != null)
{
Console.WriteLine("Downloaded file successfully, writing to hard drive...");
for (int i2 = 0; i2 < 5; i2++)
{
string filePath2 = string.Format(@"C:\Users\xn\Downloads\icuin44_legacy({0}).dll", i2.ToString());
if (File.Exists(filePath2))
File.Delete(filePath2);
using (FileStream fs = new FileStream(filePath2, FileMode.Append, FileAccess.Write))
{
fs.Write(res.FileBinaryList[i2].FileData, 0, res.FileBinaryList[i2].FileData.Length);
fs.Close();
fs.Dispose();
}
Console.WriteLine("Wrote file successfully to the hard drive.");
}
}
stopWatch.Stop();
Console.WriteLine("time elapsed running legacy functions: {0}", stopWatch.Elapsed.ToString());
Console.WriteLine("Press any key to continue...");
Console.ReadLine();
}
}
}
Yes, it was amusing at the time because even then dbrand was well known for stealing the designs of products from other companies. That’s what they do.
Didn’t Dbrand once complain that Casetify was ripping off their designs a well?
seems pretty bad of them to try and get around Valve’s copyright this way with that in mind.
Question
sathenzar
I switched to WCF b/c I've heard it's much faster then asmx. Also the WCF is configured to use MTOM while the asmx service is not. My WFC service call takes about 1 min 20 seconds to complete on a file download (streaming it in chunks) and my old asmx service takes 1 min 7 seconds to just return one massive response of embedded byte data. I'm downloading a 1.5 MB file 5 times with both calls.
static void Main(string[] args) { ServiceReference3.TestCloudWebSvcClient client = new ServiceReference3.TestCloudWebSvcClient(); client.Open(); Console.WriteLine("Getting file blocks..."); System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch(); stopWatch.Start(); for (int i = 0; i < 5; i++) { byte[] fileChunkData = null; int offset = 0; int totalBytes = 0; bool moreDataAvail = true; string filePath = string.Format(@"C:\Users\\Downloads\icuin44({0}).dll", i.ToString()); if (File.Exists(filePath)) File.Delete(filePath); using (FileStream fs = new FileStream(filePath, FileMode.Append, FileAccess.Write)) { while (moreDataAvail == true) { Console.WriteLine("More data avail is true for iteration " + i.ToString() + ", executing command..."); string errorMsg = client.DownloadLargeFile(128000, "", "icuin44.dll", 5, offset, "", "", out moreDataAvail, out fileChunkData); Console.WriteLine("Command executed. Error Msg: {0} | Block length: {1}", errorMsg, (fileChunkData != null) ? fileChunkData.Length.ToString() : "null"); // Now that we have the new byte data (assuming the call worked), lets write it to the stream. if (fileChunkData != null) { fs.Write(fileChunkData, 0, fileChunkData.Length); offset += 128000; totalBytes += fileChunkData.Length; } Console.WriteLine("Wrote {0} bytes for a total of {1} bytes to file stream...", fileChunkData.Length, totalBytes); } fs.Close(); fs.Dispose(); } } stopWatch.Stop(); Console.WriteLine("Time elapsed while running functions: {0}", stopWatch.Elapsed.ToString()); stopWatch.Reset(); client.Close(); Console.WriteLine("Closed client successfully"); Console.WriteLine("Attempting to download file via legacy service..."); stopWatch.Start(); ServiceReference4.TestWebSvcSoapClient client2 = new ServiceReference4.TestCloudWebSvcSoapClient(); ServiceReference4.DownloadFilesResponse res = client2.GetDirectSvrFiles("", "", new ServiceReference4.FileSvcDef[] { new ServiceReference4.FileSvcDef() { DirPath = "", FileLastSyncDate = new DateTime(2012, 5, 9), FileName = "icuin45.dll" }, new ServiceReference4.FileSvcDef() { DirPath = "", FileLastSyncDate = new DateTime(2012, 5, 9), FileName = "icuin45.dll" }, new ServiceReference4.FileSvcDef() { DirPath = "", FileLastSyncDate = new DateTime(2012, 5, 9), FileName = "icuin45.dll" }, new ServiceReference4.FileSvcDef() { DirPath = "", FileLastSyncDate = new DateTime(2012, 5, 9), FileName = "icuin45.dll" }, new ServiceReference4.FileSvcDef() { DirPath = "", FileLastSyncDate = new DateTime(2012, 5, 9), FileName = "icuin45.dll" }}); if(res.FileBinaryList != null) { Console.WriteLine("Downloaded file successfully, writing to hard drive..."); for (int i2 = 0; i2 < 5; i2++) { string filePath2 = string.Format(@"C:\Users\xn\Downloads\icuin44_legacy({0}).dll", i2.ToString()); if (File.Exists(filePath2)) File.Delete(filePath2); using (FileStream fs = new FileStream(filePath2, FileMode.Append, FileAccess.Write)) { fs.Write(res.FileBinaryList[i2].FileData, 0, res.FileBinaryList[i2].FileData.Length); fs.Close(); fs.Dispose(); } Console.WriteLine("Wrote file successfully to the hard drive."); } } stopWatch.Stop(); Console.WriteLine("time elapsed running legacy functions: {0}", stopWatch.Elapsed.ToString()); Console.WriteLine("Press any key to continue..."); Console.ReadLine(); } } }Link to comment
https://www.neowin.net/forum/topic/1076485-cwcf-wcf-is-producing-slower-results-then-legacy-asmx-service/Share on other sites
1 answer to this question
Recommended Posts