Click to See Complete Forum and Search --> : [RESOLVED] Use of Web Services
mnopups
October 11th, 2007, 04:37 PM
Hi,
I have a VB form with a RichTextBox defined on it. My program needs to import a data file and based on that data file, it will make various web service calls. At the completion of each web service call, an additional text string is appended to the RichTextBox control. I am calling me.refresh followed by application.doevents to force the form to repaint in between web service calls. This has almost fixed the problem where the form does not repaint itself as needed.
The problem that remains is that if the form is moved or it is temporarily overlayed by another window, it will not repaint until the currently running web service completes.
I am hoping that multi-threading will resolve this problem by using one thread to manage the form and a second thread to make the web service calls. Unfortunately, I do not have any experience with using threads in VB (although I am fluent in multi-threadaed programming concepts from my mainframe programming days).
Does anyone have any thoughts on whether this will resolve my refresh problem? Also, can you provide any sample VB code to attach/detach and manage multiple threads?
Thank you!
John
Arjay
October 11th, 2007, 05:11 PM
By VB, are you referring to VB6 or VB.Net?
mnopups
October 11th, 2007, 11:40 PM
I am using Visual Studio 2005 so I would like to say VB.Net. Is there some "magic" way to check which I am using?
Arjay
October 12th, 2007, 01:44 AM
Since you are using VB.Net, you can call the Asynchronous web service methods.
Open up the equivalent reference.cs file that was created when you added your web reference.
You'll notice your methods have been separated into two methods: one starting with Begin and the other with End.
To call the web method asynchronously, just call the BeginXXX method, and supply IAsyncResult callback.
Search google or msdn for exact code in vb.
mnopups
October 13th, 2007, 01:03 AM
Ok, the file is actually called reference.vb but there are no references to Begin or End methods that I can use to make asynchronous calls. I am not using WSDL.EXE to generate these reference files as VS2005 is supposed to do this for you when you add the Web Reference to the project. Can you think of any reason why VS2005 will not include the asynchronous method definitions when it generates the proxy?
Here are the methods that I do see in the reference.vb file:
Public Function myWeb
Public Overloads Sub myWebAsync
Private Sub OnGetmyWebOperationCompleted
I have searched google and msdn but have found no help and there is little point in trying to write the actual code unless I have the asynchronous method definitions.
Arjay
October 13th, 2007, 03:23 AM
Ok, the file is actually called reference.vb but there are no references to Begin or End methods that I can use to make asynchronous calls. I am not using WSDL.EXE to generate these reference files as VS2005 is supposed to do this for you when you add the Web Reference to the project. Can you think of any reason why VS2005 will not include the asynchronous method definitions when it generates the proxy?
Here are the methods that I do see in the reference.vb file:
Public Function myWeb
Public Overloads Sub myWebAsync
Private Sub OnGetmyWebOperationCompleted
I have searched google and msdn but have found no help and there is little point in trying to write the actual code unless I have the asynchronous method definitions.The one you need to call is myWebAsync.
mnopups
October 13th, 2007, 11:35 AM
Arjay,
Thank you for your help!I found out that VS2005 no longer generates the Begin and End methods by default because there was a switch away from that method of asynchronous programming to event-driven programming methods. This explains the missing Begin and End methods and the appearance of the "Async" method. As you suggested, I will use the Async method and control the processing between the threads using events.
However, I wanted to at least document a way that I found (it was not easy) to "activate" the generation of the older Begin and End methods that were used prior to VS2005:
1. Close the project in VS2005 and edit the project file (.vbproj) directly in an editor such as notepad (Note: Make sure you keep a backup copy of this file before proceeding).
2. Locate the "PropertyGroup" section that contains the "ProjectGuid" property and add the following record to this section:
<WebReference_EnableLegacyEventingModel>true</WebReference_EnableLegacyEventingModel>
3. Save the file and reload the project in VS2005.
4. Finally, regenerate the proxy code by updating the web reference(s).
John
codeguru.com
Copyright 2007 Jupitermedia Corporation All Rights Reserved.