Showing posts with label external. Show all posts
Showing posts with label external. Show all posts

Wednesday, March 28, 2012

calling external webservice

Hi all,

I'am still working with the beta 2 version of Ms Ajax and i have question about making a call to an external webservice. Is it possible to make a call to an external webservice from javascript without a bridge file in RC. If not will it be possible in the future?

Thanks in advance!

In the current release, it's not possible to call an external web service without the bridge (seehttp://ajax.asp.net/docs/mref/P_System_Web_UI_ServiceReference_Path.aspx for more info) and for RTM this will probably continue like this, as you can see in this whitepaperhttp://ajax.asp.net/files/AspNet_AJAX_CTP_to_RC_Whitepaper.aspx#link4, in the client networking feature.

Regards,

MaĆ­ra


Hi Maire,

Thanks for your response!!

Regards


Actually you can call an external web service! Check out this article:

http://www.xml.com/pub/a/2005/12/21/json-dynamic-script-tag.html

I hope it helps,

Bogdan


Hi Bogdanb,

Thanks for your reply. Your example is an AJAX example and not a MS AJAX example. In AJAX it is possible to do a call to a webservice directly. MS AJAX simplefies this call for me. I want to use MS AJAX and call an external webservice. Right now i'am using a bridge file to make it work. i wanted to know if this will change in the future.

Regards,

calling external javascript functions/ library from within an update panel

I have an application with a large number of javaScript functions that reside in external .js files. User controls that reference these files work perfectly.

When usercontrols inside updatepanels call the external javascript functions and libraries, they fail with 'object not found' errors.

I tested using the scriptmanager.registerclientscriptblock by adding a concatenated string with a simple function and it worked. But this is a bad way to do things both from a debugging standpoint as well as ease of code. There must be a better way?

Dim scriptTextAsString

scriptText = _

"function prepareToClose() {"

& _

"alert('prepare to close');"

& _

"test();"

& _

" }"

System.Web.UI.ScriptManager.RegisterClientScriptBlock(

Me.btnLoad,Me.GetType(),"prepare_close", scriptTextTrue)

btnLoad.Attributes.Add(

"onCLick","prepareToClose(); return false;")

What is the best way to do this?

Unless someone has a better solution, here is what I did. Basically, I load the external file into a string and use the rgisterScriptBlock...everything works well and there is still just 1 instance of the scripts for easy maintenance and other non-ajax pages can use them. Here is the code for anyone interested.:

System.Web.UI.ScriptManager.RegisterClientScriptBlock(Me.btnClose, Me.GetType(), "objectives", regLongScript("objectives.js"), True)


...

Private Function regLongScript(ByVal incoming_name As String) As String
Dim objStreamReader As IO.StreamReader
Try
Dim file_name As String = ""
file_name = Request.PhysicalApplicationPath & "a\js_scripts\" & incoming_name
objStreamReader = File.OpenText(file_name)
Return objStreamReader.ReadToEnd()

Catch ex As Exception
Return ""
Finally
objStreamReader.Close()
End Try
End Function


Here's how I've been doing it:

ScriptManager.RegisterStartupScript(

UpdatePanelTest,

UpdatePanelTest.GetType(),

"keyValue",

"alert('test')",

true);


Here's how I've been doing it:

ScriptManager.RegisterStartupScript(

UpdatePanelTest,

UpdatePanelTest.GetType(),

"keyValue",

"alert('test');",

true);

Saturday, March 24, 2012

Call an external web service from AJAX

HI,

I have tried ServiceReference element in ajax but it allows me to use a webservice if its part of the same project only.

What if i ahve a seperate webservice project and i want to refere webmethod from that service?

How i can call a webmethod that is in service outside of my project?

THanks,

You write a wrapper WebService to call the external one. While there is a constraint on JavaScript calling external WebServices, there's nothing to stop your WebService calling external WebServices.

Write yourself a WebService which can be called from your JavaScript then have that WebService call the external one, passing the results back to your javascript

You'll need to use the WebRequest and WebResponse objects in your WebService, or maybe you can set up a proxy in the same way you'd reference a WebService in the normal way


Hi,

the following article might help:

http://dotnetslackers.com/columns/ajax/MashitUpwithASPNETAJAX.aspx