简体   繁体   中英

How to call a web service in “fire and forget” way from ASP.Net

I have a web service that I want to call from one of my asp.net classes. I can call my web service successfully.But now I need to call this service asynchronously. I need to call it and NOT wait for the service to complete execution. I don't need to process a response from the service and don't need to verify if the service executed successfully. All I want is to be able to call the service and be free to do other things.

You need to consume web service asynchronously. Goto and check

AddServiceReference -> Advance -> generate asynchronous operations.

after this async callback events will be available to you for every method Suppose you have ABC method in you service when you will consume it by as sync these methods will be available to you in your application

1>ABC (fire and wait for output)
2>ABCAsync(fire and forget)
3>ABC callback event(get fired <if ABCAsync is called> when data available in your application)

One way to implement a fire-and-forget approach is to use the IsOneWay property on the OperationContract attribute, like this:

[OperationContract(IsOneWay=true)]
public void SomeMethod(string someValue);

When set to true, the operation won't return a message. Note that methods marked as one-way cannot have return types or ref or out parameters (which makes sense). It also should not be confused with asynchronous calls, because it's not the same thing (in fact, a one-way call can block on the client if it takes a while to get a connection, for example).

See OperationContractAttribute.IsOneWay Property for more information.

Have you tried this:?

http://msdn.microsoft.com/en-us/library/bb885132(v=vs.110).aspx

this is another way to do it, check it out.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM