VS 2005 - Return Value From Asynchronous Web Service Call
Aug 13, 2009
I'm using ASMX web services in VB.Net in VS 2005. I am calling a function method on the web service that returns a true or false value. This works fine if I call the the web method synchronously, but if I want to call the method asynchronously, the function returns to a sub and there is no return value; therefore, I can't tell whether the result of call is true or false. Is there a way to make an asynchronous call and still get the true or false result (perhaps using the userState Object)?
For Example:
Dim MyResult as Boolean = MyService.GetResult(10)
Dim MyResult as Boolean = MyServer.GetResultAsync(10)
This doesn't work the compiler complains: "Expression Does Not Produce a Value"
Background: My application is used to execute tests using Selenium RC servers, and occasionally I'm running into a problem when my call to a Selenium command doesn't return the response from the RC server - it then ends up blocking the thread that is executing the test.
I have a Class in a Windows Form project. I would like to call the class return value from the Form1 sub on button click. How do I do that? Lets say I would like to display the Return in a MsgBox?
I have been trying to figure this our for far too long and I cannot get my head around it. Every example I have seen seems to be far more complex that I need. I have a web service in my project (.asmx). I want to call it very simply from a button on a webpage.
Click Run service asynchronously return control back to webpage (web service running in background)
I need to make an asynchronous call to a method which for the sake of simplicity counts from 1 to 100. If an exception is thrown during the methods counting process, lets say at 50 I need to stop the methods execution, dispose of a few objects and restart it at 51 but have no idea how to go about it.I basically need to raise an event from the method to the main thread and restart the asynchrounous method.
VB.NET 2010, .NET 4/I have a System.Timers.Timer object that does some work on its elapsed event:
Private Sub MasterTimer_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles MasterTimer.Elapsed MasterTimer.Enabled = False '...work... MasterTimer.Enabled = True End Sub
My problem is that the work that it's doing sometimes gets stuck. Part of the work is serial communication so it might be getting stuck waiting for a response from something. I've already modified my serial communication code a bit to hopefully solve the problem. However, this timer is basically the heartbeat of a production control application and it is very bad if it were to stop for any reason. I was thinking that it might be nice to put in a fail-safe timeout so that, if the "work" is taking too long, the timer could re-enable itself and try again. I was thinking of something like this:Move the work into a subroutine and create a delegate:
Private Delegate Sub WorkDelegate() Private Sub Work() '...work... End Sub
Call the work by invoking the delegate and then use WaitOne(timeout) on the IAsyncResult to specify a timeout:
Private Sub MasterTimer_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles MasterTimer.Elapsed MasterTimer.Enabled = False Dim workDel as New WorkDelegate(AddressOf Work)
[code]....
In that it would re-enter a subroutine that is already running? Is there a way to abort Work() if it hasn't finished after the timeout? In other words, just cease execution of Work() if result.IsCompleted Is False after WaitOne?
I just have a simple vb.net website that need to call a Sub that performs a very long task that works with syncing up some directories in the filesystem (details not important).
When I call the method, it eventually times out on the website waiting for the sub routine to complete. However, even though the website times out, the routine eventually completes it's task and all the directories end up as they should.
I want to just prevent the timeout so I'd like to just call the Sub asynchronously. I do not need (or even want) and callback/confirmation that it ran successfully.[code]...
I inherited a working WCF Web Service with one major flaw - the WCF Service consumes memory and does not release unless the service is restarted. After a half a day of requests hitting the web service, the memory on the server hosting the service climbs to close to 2 gig and is dead in the water.
I'd like to be able to release memory after the web service has received its response but cannot figure out how (WCF is still new to me). [code]...
I am trying to communicate with a Windows service on a remote machine on the network but i keep getting an exception saying the following: "System.InvalidOperationException: Cannot open Service Control Manager on computer 'machine001'. This operation might require other priviledges. ---> System.ComponentModel.Win32Exception: Access is denied.
Service1.svc Public Class Service1 Implements IService1
[code]....
For some unkown reason, I can run the VS 2010 client test and it the WCF host works fine. The code above just returns nothing (it's supposed to return a string)
I need to dynamically call web service! For this I made simple web service Service1.asmx
Then I created the proxy class for the Service1 Web Service, I use the WSDL.exe utility and following command at the command prompt: wsdl /language:VB /out:myclass.vb http://localhost:3245/Service1.asmx?WSDL
This command create class myclass.vb. That class I include in my Windows Application project, but when I do this I get lot of errors.
This is the how created class look like:
Imports System Imports System.ComponentModel Imports System.Diagnostics Imports System.Web.Services
This is the function that I use in web service for getting current windows user.
<WebMethod()> _ Function User() As String Dim p() As String = Split(My.User.Name, "")
[code]....
When I run service on localhost it realy return current windows user name!The problem is when i run service from remote PC, in that case I got nothing from this function. What is problem with this service, and how I can get name of Windows user?
I have a windows app that references a web service I created. In the web service, I created a function that needed to return more than one value. Because of this, I created a public structure in the web service: Public Structure MyRecordSet Public lstOfDataInRecord As List(Of String) Public iNumberOfRecords As Integer End Structure
Here's the function - the return value is MyNewRecordSet: Dim MyNewRecordSet As MyRecordSet <WebMethod()> _ Public Function GetDataReturnList(ByVal sql As String, ByVal sTableName As String) As MyRecordSet MyNewRecordSet.lstOfDataInRecord = New List(Of String) [Code] ..... Anyway, I see it's a conversion issue, but not sure how to resolve it. This is my first attempt to use a public structure in a web service and receive a return on it from my app.
This is annoying. I'm trying to put a wrapper around some functionality that uses a web service to return some information. The intention is to wrap all of that communication into a dll such that the user can simply call functions from the dll to get back information, without needing to care about the service.As far as I can tell, that isn't possible, because the service information, as far as bindings and endpoints, HAS to exist in the app.config of the program that references the dll. That means that anybody using this dll won't just be able to add a reference to it and use it, like they would with any other kind of dll, they must also edit their app.config to add in a bunch of information. That's a simple copy and paste job, but it's incredibly unfriendly, and exposes some of the internal workings of the dll to casual inspection.
So I have an application that uses a webservice, On the UI side the user picks a table which sends a request across the web to my webservice to return the fields of this table. So after this request is accomplished I have, on the webservice side a series of Name,Type Pairs that I need to serialize and send back to my client. I could use a List(of String()) to send the values back but I want to use a List(of Custom_Class) instead because later I have to do this on a much larger scale and I want to learn on this simpler version.
Iam trying to make a call to a thred by does not find how to start a Thred on a Function that should have a value and should return a value,I got it to work on Function or Subs that does not pass or return values.
Like this (Exampel)My Function TEST ( byval Par1 as integer ) as integer Par1 = par1 * 100 Return Par1 End Function
The call Public Thred1 As System.Threading.Thread Thred1 = New System.Threading.Thread(AddressOf TEST (10) ) ' Does not work Control.CheckForIllegalCrossThreadCalls = False Thred1.Start()
How do a get the return value from my Function in a thred?and it seems like the System.Threading.Thread does not like fuctions with parameters?
Should I call .Dispose() after returning an object that implements IDisposable? [code]In other words, is the object I return a copy, or is it the object itself?
I have a Web Service with one WebMethod for which return value is boolean.It accepts XML file as string and process data. How can I first return status as true and then call the ProcessData method.
As the processing data takes time I need to return true first and then process the data.
[webmethod] Public function receiveData(ByVal xmlstr as string) as boolean dim status as boolean=false try
I have a console app that is supposed to async call a web service...i don't get any errors but the completed handler doesn't seem to complete correctly. I have a subroutine with a loop that is supposed to fire off say 6 seperate calls to another routine that calls the service. The completed event handler routine puts data into the database..If i put a thread.sleep under the call to the routine calling the web service. The completed event handler fires but only one record is put in the database instead of the hundreds expected and only that one webservice call appears to fire.I should mention that this works as expected when calling the sync method of the web service within a console app and the asyc calls work as expected from a windows forms app. I just need it to work async within a console app..
I'm working in VB.Net and I'm trying to make a piece of code more generic.In fact, there's a big Select Case statement that build a ProxyServer based on a value passed in parameter (a string).
Select Case _strNteraHL7 Case Constantes.NomPRPMIN306010 strUrl = ObtenirUrl("ProviderDetailsQuery", _strVersion, _strEnvir, True, _blnSimulCAIS, _blnSimulPDS, _blnSimulPDSSIIR, _blnSimulPDSInteg)
[code]....
or something similar, so I can remove all those big switch cases, that repeat the same thing 30 times.objWsHL7 being an object or type "object" at compiling.Again, in another switch case statement,
objMsgHL7Out = _objWsHL7.ProviderDetailsQuery(_objMsgIn) objMsgHL7Out is a System.ServiceModel.Channels.Message _objMsgIn is a System.ServiceModel.Channels.Message _objWsHL7 is an Object
I have a asp.net web application with jquery controls. I have a datagrid that will display data from a database table and created a WCF Service to access the db and return the data. I want to be able to call the WCF service from this application which is on a different server and have the xml data returned, converted to json format to be used in the datagrid which is a jquery widget. I have tested the web service and it works fine. Should I call the web service from the javascript function within the xml or create a .net method behind that calls the service and then does the conversion? From these how would I get started?