Answered by:
Call web service Asynchronous

Question
-
User-275454158 posted
Hi,
I'm having my web service inside my asp.net application root directory. I want to call a web service method from my asp.net application on button click. I don't want any output from this method. I just want to invoke the method. The method is going to call another web service. The process will take long time.
In this case i'm calling the web service from my application, here my application is waiting for the response from the web service. I don't want to wait for the response from the web service. How can i achieve this. Kindly guide me how can i proceed further. Thanks.Wednesday, November 20, 2013 5:17 AM
Answers
-
User-484054684 posted
Option 1: If you are using normal asmx webservices, then, just decorate your webMethod this way: [ SoapDocumentMethod(OneWay=true) ]
<%@ WebService Language="C#" Class="Stats" %> using System.Web.Services; using System.Web.Services.Protocols; public class Stats: WebService { [ SoapDocumentMethod(OneWay=true) ] [ WebMethod(Description="Starts nightly statistics batch process.") ] public void StartStatsCrunch() { // Begin nightly statistics crunching process. // A one-way method cannot have return values. } }
Option 2: However, you may also like to use BeginXYZ and EndXYZ methods but that uses additional memory that is not used if you don't want to process return type.
Reference: http://stackoverflow.com/a/5037048
If you want to know in detail on how to use BeginXYZ and EndXYZ methods: http://msdn.microsoft.com/en-us/library/aa480516.aspxYou may also have a look at C# 4.5 feature, for other ways: http://msdn.microsoft.com/en-us/library/vstudio/hh156513.aspx
Please mark this as answer if this answers your question.- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, November 20, 2013 7:04 AM -
User-488622176 posted
Alternative:
- use WCF (forget about ASMX)
- Define a one-way service operation : http://msdn.microsoft.com/en-us/library/system.servicemodel.operationcontractattribute.isoneway(v=vs.110).aspx
This will make the call without waiting for the result.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, November 22, 2013 9:31 AM
All replies
-
User-484054684 posted
Option 1: If you are using normal asmx webservices, then, just decorate your webMethod this way: [ SoapDocumentMethod(OneWay=true) ]
<%@ WebService Language="C#" Class="Stats" %> using System.Web.Services; using System.Web.Services.Protocols; public class Stats: WebService { [ SoapDocumentMethod(OneWay=true) ] [ WebMethod(Description="Starts nightly statistics batch process.") ] public void StartStatsCrunch() { // Begin nightly statistics crunching process. // A one-way method cannot have return values. } }
Option 2: However, you may also like to use BeginXYZ and EndXYZ methods but that uses additional memory that is not used if you don't want to process return type.
Reference: http://stackoverflow.com/a/5037048
If you want to know in detail on how to use BeginXYZ and EndXYZ methods: http://msdn.microsoft.com/en-us/library/aa480516.aspxYou may also have a look at C# 4.5 feature, for other ways: http://msdn.microsoft.com/en-us/library/vstudio/hh156513.aspx
Please mark this as answer if this answers your question.- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, November 20, 2013 7:04 AM -
User-488622176 posted
Alternative:
- use WCF (forget about ASMX)
- Define a one-way service operation : http://msdn.microsoft.com/en-us/library/system.servicemodel.operationcontractattribute.isoneway(v=vs.110).aspx
This will make the call without waiting for the result.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, November 22, 2013 9:31 AM