0

In Webservice is it possible to call javascript function. [Or] In Webservice is it possible to redirect page. I have used this(System.Web.HttpContext.Current.Response.Redirect("~/Error.aspx");), But, i didn't find any sol for it. Please, reply as soon as possible.

8
  • Are you mistaken WebApplication for WebService? Commented Jun 2, 2015 at 6:46
  • In Web service only. Rohit Commented Jun 2, 2015 at 7:06
  • How to create a global exception handler for a Web Service Commented Jun 2, 2015 at 7:13
  • In your global.asax, return the corresponding HTTP error code with message. Commented Jun 2, 2015 at 7:48
  • When we get any error in web service Catch it is not navigating to global.ascx.cs page Commented Jun 2, 2015 at 7:52

1 Answer 1

1

You can't call JS function from WebMethod.

But there is a trick you can set your Webmethod response in such way that on the success it returns some parameter or your URL which you want to redirect.

Something like

success: function(response){
  var r=response.d;
  window.location.href = r;
} 

Or

You need to build a SOAP extension.

Application_Error never fires for WebService

The reason for this is that the HTTP handler for XML Web services consumes any exception that occurs while an XML Web service is executing and turns it into a SOAP fault prior to the Application_Error event is called. To achieve exception handling you need to write a custom SOAP extension or HTTPModule.

Check this links:

  1. Throwing Better .NET Exceptions with SOAP and HTTP
  2. User-Friendly ASP.NET Exception Handling
Sign up to request clarification or add additional context in comments.

7 Comments

SOrry, In datatable we cannot handle any return. that's y i need to handle in webservice only.
How to create a global exception handler for a Web Service
I need to handle error in catch & then i need to navigate it to other page using webservice.Where I have this( //catch (Exception ex) //{ //System.Web.HttpContext.Current.Response.Redirect("~/Error.aspx");), But, it did not worked me
You need to build SOAP extension to catch Exception, which occurs in your Webservice
Ya, I used it. But, it is unable to catch the exception in Global.ascx.cs page. I have used like this( void Application_Error(object sender, EventArgs e) { Response.Redirect("~/Error.aspx");). Error in Web service it is not going to Global.ascx page.. Thank You for ur quick reply(Satinder).
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.