Invoke web service method without waiting for it to finish - asp.net

I have ASP.NET 2010 (VB.NET) web-service having a method "Method1".
I need to invoke that method from Windows application (VB.NET 2010) without waiting for the method to end execution, also do not need to get the return value of the method. Just need to invoke it and that's all.
What is the best way to do that?

If you edit your question giving more information about your needs, maybe some code that you're pretending to use, it should be easy to help you.
So, without that information I can assume that maybe investing about asynchronous methods should be helpful for you. It's not just about put async keyword...
You can find more information from here:
https://social.msdn.microsoft.com/Forums/sqlserver/en-US/5179579a-492b-4aad-babe-fdef854b68b3/c-50-calling-a-method-without-requiring-to-wait-for-it-to-finish-nor-its-results?forum=csharpgeneral
Hope to be useful... Greetings.

Related

ASP.Net How to call an Unknown (Dynamic) WSDL Webservice and parse it's result?

will appreciate any pointers here. This scenario may sound a bit weird:
I am trying to write a program that consume webservices that user define, and that my program do not know in advance.
For example, my program allow users to set/define all the webservices that they have in their network, into my database.
My program will then show a list of all the webservices that users have defined, and with a click, my program will call THAT webservice (with the parameters that use can key in) and then my program will show the result (string).
Problem is that at design time, I have no idea what are the webservices and the parameters and response. So, I need to dynamically create some sort of a stub that can consume these webservices without having to Add-Reference into my project in advance.
Will appreciate any pointers here.
Sounds like you're trying to build your own SOAP_UI here :) (excellent tool for testing purpose on Webservices) , correct ?
I guess you'd want to play with wsdl.exe.

Check if a webservice exists

Could someone please be kind enough to show me the best way to determine if a webservice (ASP.NET) exists at a given URL?
I assume an approach will be something along the lines of issuing a request using System.Net.Webclient but how could I determine if it is a valid webservice and what sort of request should I issue?
EDIT: To add a bit more context I am determining if a webservice exists because I am attempting to build a generic tool that uses arbitrary webservices.
The only way IMHO to be sure the service is up is to be able to call an innocuous method on the service and verify the response. Retrieving the WSDL is not sufficient.
There is a similar SO question on this here:-
How do I test connectivity to an unknown web service in C#?
I would ask for WSDL document. If you get it back it means that the service exists and you can check to WSDL for implemented methods.
Consider reading about WS-Discovery
http://docs.oasis-open.org/ws-dd/discovery/1.1/wsdd-discovery-1.1-spec.html

Webmethod authentication not passed

I'm new to this AJAX approach when you're not supposed to use UpdatePanel but rather go with WebMethods and WebServices. My main problem is authentication.
When page is entered or postback request is created, everything works fine. Authentication is passed correctly and I can access Thread.CurrentPrincipal.Identity and get my user identity object from there.
However this changes when I try to call WebMethod on my page. Call is passed correctly to server and everything seems to work just fine until i try to get user identity from thread. Then I get just Anonymous user instead of real one. Enabling session on webmethod didn't seem to help much.
Any ideas what might cause this problem and how to solve it? Someone mentioned that authentication cookie needs to be passed along with the request, but how am I supposed to do it?
Any help will be appreciated.
Edit:
Some clarification and code:
My application is written in standard asp.net. After some deeper research in legacy code I've found out, that all authentications are done in some base class from wchich all other pages inherit. Each time page is loaded, user principal are obtained from HttpContext.Current.Session("..."). I think this is far from good solution, but I'll need to stick with it right now. Problem was, WebMethod is not firing whole page lifecycle since it's static. I've fixed it right now by calling method that obtains user data from session.
I would like to get some ideas how this could be created correctly and what problems might be result of session based authentication.
PageMethods.SomeMethod(parameter, SuccessDelegate, FailureDelegate);
This is how I'm calling WebMethods right now. I assume it's passing all required cookies, am I right?
It depends on how you're calling the method and in what manner?
Jquery for instance with its Post method should push all cookies (including your FormsAuth / Session cookie) up with the request that should still authenticate as appropriate. Bare metal techniques might be making lightweight calls that simply do not push the cookie up...One way to monitor this is by using Fiddler to observe the request and a browser based development plugin like Firebug and see what is occuring and amend your JS code as appropriate.
Personally, if you are starting a brand new project and there is no pressing need to expose your services beyond your web application then I would suggest looking at ASP.NET MVC where you can make Jquery / client-side up to the controller and get your authentication wrapped up for free. I've recently created something simliar using WCF JSON endpoints and some inevitable pain, I then saw MVC and kinda kicked myself...
As noted in comment above, the issue lies in legacy code that handles users. It is needed to make call to special function that assigns appropriate user data to handling thread. Not a best solution, but that's how it sometimes is with legacy code. What you gonna do?

how to create a singleton asmx service

how can i create an singleton asmx webservice ? (please don't say use WCF and WWF :D )
Short Answer: You don't want to.
Long Answer: A request to an .ASMX is going to non deterministically use a new worker thread, so even if you used the singleton pattern, the life of the singleton will not be known.
Perhaps elaborate on what you want to do, and I can guide you towards the best pattern.
I'm not sure how a singleton solves your performance problem, unless you are caching data inside the instance. In that case, I'd agree with the above suggestion of introducing the cache between the service and the database. Just how mutable is this data?
I won't suggest WCF, but only because you asked us nicely not to.
I will mention that you've found yet another reason to use WCF over ASMX. You might want to keep a list.
You might also want to keep a list of reasons to use ASMX over WCF. You might even want to use the same list for the reasons not to upgrade to .NET 3.5 SP1. It won't be a long list.
There may come a time, when Management wonders why certain things take so long to accomplish, when you'll want to send them your list.
You could use an ashx (HttpHandler). Implement IHttpHandler and set IsReusable to false.
http://neilkilbride.blogspot.com/2008/01/ihttphandler-isreusable-property.html
Depending on what you want to do, maybe you can write the engine as a singleton that's accessed by whatever thread services the ASMX call.

Implementing a custom Windows Workflow activity that executes an asynchronous operation

I'm having some conceptual trouble on figuring out how to best implement this... I want to create a custom Activity class for Windows Workflow. The activity has to call out to a third party library method that itself runs another process asynchronously and may take anywhere from seconds to many hours to complete. This library offers the ability for me to either poll for the method result or to subscribe to an event that indicates its completion. In my non-workflow apps, I typically just subscribe to that event, but that doesn't seem to be reasonable in the workflow case. I'm also not sure exactly how to best implement a polling scheme. Can someone recommend some pointers to similar problems?
Kirk Allen Evans wrote an interesting blog about this with some pretty good code examples.

Resources