Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5643
  • Last Modified:

VB.NET Calling Asynchronous Webservice



I have an ASP.NET/VB.NET program.  There is a webservice does processing in a separate project which does not return any values.  The webservice is executed upon clicking the run button on a certain page,  however I would like the webservice to be executed in the background while the next line of code is processed on the client in concurently.

I had seen the solution for a similar post that utilized the:  <WebMethod(), SoapDocumentMethod(Oneway:=True)> _ method heading prepended on the webmethod that needs to be executed asyncronously.  That worked for me as the code after calling the webservice got executes.  However as the webmethod gets executed concurently, it is running on an Domain\ASPNET which fails to map/access the m:\.  

Before I referenced SoapMethodDocument,  the Domain\UserName the webservice was under is the one  used under impersonation which access the M: fine.

So therefore my question is how I can refernce the SoapMethodDocument in the webservice so it runs concurrently under the domain\UserName i used for impersonation.  And is there any other way i can execute my webservice concurrently?  I've been through almost every single post on the internet.

Please advise.

Sincerely,

Cataztrophe









0
cataztrophe
Asked:
cataztrophe
  • 6
  • 6
1 Solution
 
Bob LearnedCommented:
With the web service proxy, there are asychronous methods automatically generated, and don't require any web method decoration attributes.

Bob
0
 
cataztropheAuthor Commented:
Yes I was aware of that.  I had tried setting Async = "true" on the aspx page that executes methodNameAsync function generated by the proxy as follows:

Dim ws As New webserviceclass
ws.PreAuthenticate = false
ws.Credentials = New System.Net.NetworkCredential("UserName", "Password")
ws.MethodNameAsync(CType(Session.Item("xDocument"), XmlDocument))

However this gives me the same result as executing the webmethod with ws.MethodName.  The webservice still would not execute asynchronously.  I am wondering if I am doing this properly.  Is there an example you can show me?

0
 
Bob LearnedCommented:
That is strange, because I have a C# web service, and the proxy was generated like this:

      /// <remarks/>
        public void AddDocumentAsync(Property[] metadata, string documentClass, object userState) {
            if ((this.AddDocumentOperationCompleted == null)) {
                this.AddDocumentOperationCompleted = new System.Threading.SendOrPostCallback(this.OnAddDocumentOperationCompleted);
            }
            this.InvokeAsync("AddDocument", new object[] {
                        metadata,
                        documentClass}, this.AddDocumentOperationCompleted, userState);
        }

       private void OnAddDocumentOperationCompleted(object arg) {
            if ((this.AddDocumentCompleted != null)) {
                System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
                this.AddDocumentCompleted(this, new AddDocumentCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
            }
        }

You will notice the call to InvokeAsync, and the AddDocumentOperationCompleted event handler for the completion of the web service method call.

Bob
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
cataztropheAuthor Commented:
Each webmethod in my webservice will have a corresponding MethodNameAsync method generated for it.  I am not able to see the implementation of MethodNameAsync methods.  The above example that I had posted was how I am currently trying to call the webservice asychronously.  When I typed in ws and then the dot, I had browsed through the list of methods, and I could even find an MethodNameCompleted or MethodNameOperationCompleted handler.  

Do you have any further suggestions for me?  Or is there any additional info that I can provide for you to help clarify my situation more?

 
0
 
cataztropheAuthor Commented:
Sorry, I do see the implementation for the methodNameAsync method and MethodNameOperationcompleted method as follows:

Public Overloads Sub RunACSAsync(ByVal xDocument As System.Xml.XmlNode, ByVal userState As Object)
            If (Me.RunACSOperationCompleted Is Nothing) Then
                Me.RunACSOperationCompleted = AddressOf Me.OnRunACSOperationCompleted
            End If
            Me.InvokeAsync("RunACS", New Object() {xDocument}, Me.RunACSOperationCompleted, userState)
        End Sub
       
Private Sub OnRunACSOperationCompleted(ByVal arg As Object)
            If (Not (Me.RunACSCompletedEvent) Is Nothing) Then
                Dim invokeArgs As System.Web.Services.Protocols.InvokeCompletedEventArgs = CType(arg,System.Web.Services.Protocols.InvokeCompletedEventArgs)
                RaiseEvent RunACSCompleted(Me, New System.ComponentModel.AsyncCompletedEventArgs(invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState))
            End If
        End Sub

However, I guess my question is how can I use this methods to have my webservice called asynchronously?
0
 
Bob LearnedCommented:
Try something like this:

Dim ws As New webserviceclass()
AddHandler ws.OnRunACSOperationCompleted, AddressOf OnRunACSOperationCompleted
ws.RunACSAsync(node, Nothing)

Private Sub OnRunACSOperationCompleted(ByVal arg As Object)
End Sub

Bob
0
 
cataztropheAuthor Commented:
Thanks Bob for taking the time to translate the C# version of the above code into VB.NET.  However, I had already tried the above code before posting which did'nt work.  I had retested it and got the same results which is the code after calling the webservice will not execute until the webservice finishes.  

Any other suggestions will be greatly appreciated.
0
 
Bob LearnedCommented:
I am not sure why this is happening, but since the thread is supposed to be asynchronous.  When you create something like a "Hello World"-type web service, with a simple method, does it do the same thing?

Bob
0
 
Bob LearnedCommented:
Also, what is the threading model for your app?

Bob
0
 
cataztropheAuthor Commented:
You are right, the code to add a handler and MethodNameAsync works.  I do beleive it is another problem causing it to look like it is not running asynchronusly since i tried placing break points after the async webservice call and the break points stops immediately.  

After executing the webservice asynchronuosly, The next line of code is a page transfer to the next progress update page.  The webservice contains 5 steps towards completion and will write the progress of these steps to a table in the SQl server.  The progress update page is set on auto refresh to display the most updated status from the database.  

If I transfer the page with response.redirect(ProgressUpdate, true), the page transfer will hold up and not transfer until webservice completed evenwhen the break point is hit in page load in the progress update page.  Using Server.transfer will transfer the page right after the webservice is called, however, since control is still within the previous page, whenever the progress update page refreshes, it will bring the page back to the previous page that called the webservice in.  I am still trying to diagnose the issue more.

Sorry for the confusion.  Do you have any insights on why that would happen?  Is there another page transfer method that I can use?
0
 
Bob LearnedCommented:
This is getting to be a more difficult question than when we first started.  It is difficult to comment on the "best" approach for a solution, without understanding what you are doing outside of calling the web method asynchronously.

Bob
0
 
cataztropheAuthor Commented:
Thanks Bob!
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 6
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now