Showing posts with label call. Show all posts
Showing posts with label call. Show all posts

Wednesday, March 28, 2012

Trapping server errors

If an asynchronous call generates an error on the server side, the client displays a Javascript alert box with the basic error message, for instance "Object reference not set to an instance of an object".

Is there any mechanism to trap and react to these errors on the client side, for instance directing them to an error page instead of showing them the alert box?

Mike

You can set in web.config

<customErrors mode="RemoteOnly" defaultRedirect="GenericError.aspx">
</customErrors>

So that client side will be rredirected to GenericError.aspx instead of getting an error...


I think you misunderstand the question. These are server side errors that occur on an AJAX asynchronous postback, rather than a regular postback, so it is not possible to redirect the client by using either the built in ASP.NET custom error page functionality, or by using Response.Redirect.

There must be some mechanism within the AJAX library for me to specify what to do in the case of an exception being raised. Really, all I want to do is, instead of the alert box showing the .NET error message, it should show something generic like "Oops, an error occured".

Can someone tell me how I do this?

Mike


Check this example, might be useful for you .

http://ajax.asp.net/docs/ViewSample.aspx?sref=Sys.Net.ErrorHandlingTutorial%23WebServiceMethodError.aspx

http://ajax.asp.net/docs/tutorials/ConsumingWebServicesWithAJAXTutorial.aspx

Saturday, March 24, 2012

Trouble canceling an Ajax webservice

I have been searching how to cancel a webservice request in javascript and the standard solution does not seem to work for me. I call the webservice like this.

_request = ClientServices.GetPolyListings(myPoints, SearchComplete, SearchFailed);

_request seems to always be undefined after I do this.. I checked the value during through the debugger and even tried sleeping the thread in the webservice to postpone it for testing. Nothing seems to work. I have this code which never executes because its undefined.

if(_request)

_request.get_executor().abort();

Try with:

_request = ClientServices._staticInstance.GetPolyListings(myPoints, SearchComplete, SearchFailed);
Check:
http://geekswithblogs.net/rashid/archive/2007/07/14/Cancel-a-Web-Service-Call-in-Asp.net-Ajax.aspx

Thank you works great. Do not know how I forgot the _staticInstance because I am pretty sure I looked at that site already. Thanks Solved.


Would you pls mark it as answer.

Wednesday, March 21, 2012

Trying to call ASP.NET AJAX WebService JavaScript

Hi,

I am trying to call the generated webservice generated javascript from a non-asp.net application. Is this possible? I would assume one would include http://www.website.net/Service.asmx/js javascript in the not asp.net application, and then make the functions calls. Would this work without a ScriptManager object?

thanks!

-sanjay

Well, you can.

However, you are the one that should make the calls instead of the ScriptManager generated javascript (ScriptResource.axd script page) .



hello.

well, i recommend that you download the js client library and add it to the page (you'll need the main js file: Microsoftajax.js file). you can get it from here the download section of the asp.net ajax site.

after adding references to the js file, you can get a proxy by using the <script> element with the path you 've set up (notice that this will only work if the web site that is hosting the web services is configured to use the asp.net ajax on the server side).


I would add the reference to "Microsoftajax.js" in the non-ASP.net app? One thing I forgot, the application calling the asp.net webservice JS proxy is in a different domain. I am not sure what affect this might have, if any.

thanks!


hello.

1. yes, you shoudl download the library and simply add the js file to your site and then add a script element on your page

2. well, not good :( the client platform has several classes the concept of executor: a "low" level class that will be responsible for making the call. when you get a web service proxy, it'll use an executor to make the call. currently, the only executor available uses the xmlhttprequest to perform the call, which means that you won't be able to do cross-domain calls. if the remote web service returns json (like for example, the yahoo services), you should be abel to leverage the script element to make a call and get the js inserted on the page.