This message was discovered on microsoft.public.dotnet.general.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
| hs |
Hi I am using the articles by Matt Powell about server side asynchronous web methods (as well as the client side article). However i dont see any improvements to the speed of my application. I'm experiencing the slow speed on the server side. I read that using a delegate to call an asynchronous method would be ineffecient and maybe causing the problem. Can someone give me some advice on what i can do to improve the speed without doing a complete rewrite (my code was based on a synchronous piece).
Thanks
server side code ---------------- public delegate string ProcessMessageXML3AsyncStub(string asMessage);
public class MyState { public object previousState; public ProcessMessageXML3AsyncStub asyncStub; } [WebMethod] public IAsyncResult BeginProcessMessageXML3(string asMessage,AsyncCallback cb, object s) { ProcessMessageXML3AsyncStub stub = new ProcessMessageXML3AsyncStub(ProcessMessageXML3); MyState ms = new MyState(); ms.previousState = s; ms.asyncStub = stub; return stub.BeginInvoke(asMessage, cb, ms); }
[WebMethod] public string EndProcessMessageXML3(IAsyncResult call) { MyState ms = (MyState)call.AsyncState; return ms.asyncStub.EndInvoke(call); }
public string ProcessMessageXML3(string asMessage) { // Go to database and fill datatable OleDbConnection dbconn = new OleDbConnection("Provider=MSDAORA.1;User ID=SQL;Password=SQL;Data Source=TestDB"); OleDbDataAdapter da = new OleDbDataAdapter("SELECT * FROM Table1", dbconn); DataTable dt = new DataTable(); da.Fill(dt); this.dt = dt; if(dt.Rows.Count > 100) { Thread newThread = new Thread(new ThreadStart(this.CreateMoreThreads)); newThread.Start(); } MemoryStream ms = CreateStream(this.dt, 0, 100);
// Do some more IO stuff ... return "something"; }
private void CreateMoreThreads() { // Create even more threads depending on the number of records returned // and do more IO stuff }
Client side ----------- private void button2_Click(object sender, System.EventArgs e) { this.webservice1 = new localhost.Service1(); this.ds = new DataSet();
AsyncCallback callback = new AsyncCallback(this.ServiceCallback); this.webservice1.BeginProcessMessageXML3(textBox4.Text, callback, null); }
private void ServiceCallback(IAsyncResult result) { localhost.Service1 ws = new localhost.Service1(); string s1 = ws.EndProcessMessageXML3(result); object[] args = {s1}; this.Invoke(new ProcessStringDelegate(ProcessString), args); }
public delegate void ProcessStringDelegate(string as1);
private void ProcessString(string as1) { // Process the string here }
|
|
| |
| |
| Tian Min Huang (VIP) |
Hello,
Thanks for your post. I reviewed your description and web methods client/server code carefully, and now I'd like to share the following information with you:
1. I believe that your design is good and efficient. I noticed that you code is based on asynchronous web methods on both client and server sides. It also seems to me that your client program is a WinForm application, and I believe using a delegate to call the web method is a nice approach which will not block the message thread for the client. That is, your application is responsive while the web method is under processing (after user clicking Button2). On the server side, it access Oracle database which is time-consuming.
2. >> However i dont see any improvements to the speed of my application.
One reason why the asynchronous method call enables the performance is that we can perform several tasks simultaneously. For example, your client application is responsive and can perform other tasks when the web method is processing on the remote system. If your application is just idle and waiting for the delegate to be called, there is no difference between synchronous and asynchronous method calls in terms of performance. It's of the same case on server side, we are able to notice the performance increase when there are several web methods calls coming in simultaneously.
Please feel free to let me know if you have any problems or concerns.
Have a nice day! :-)
Regards,
HuangTM Microsoft Online Partner Support MCSE/MCSD
Get Secure! -- www.microsoft.com/security This posting is provided "as is" with no warranties and confers no rights.
|
|
| |
| |
| Tian Min Huang (VIP) |
Hi,
I am currently standing by for an update from you and would like to know how things are going there. Should you have any questions or concerns on the recent questions/ information I've posted, please don't hesitate to let me know directly. It's my pleasure to be of assistance
Regards,
HuangTM Microsoft Online Partner Support MCSE/MCSD
Get Secure! -- www.microsoft.com/security This posting is provided "as is" with no warranties and confers no rights.
|
|
| |
|
|
|
|
|
|