Showing posts with label hooked. Show all posts
Showing posts with label hooked. Show all posts

Wednesday, March 28, 2012

calling a web service from a secure site

I have hooked into a web service from our site and it has worked fine throughout development. Now that we've pushed the site live, the page that calls the service is a secure page and I get a javascript error on a line 3210. I'm assuming it's in the Atlas.js file (since I'm using Atlas to call the web service). That line says

_requestor.open('POST', _effectiveUrl,true);

I'm not sure what to do to fix this or if it's possible to fix it since I'm calling it from a secure page. Has anyone run into anything like this before and if so, how do you get around it? Or is it impossible to call an unsecure web service from a secure page? Thanks.

The browser generally limits calls from secure to unsecure pages. Is there any way you can put the web service on the same secure site?

thanks,
David


I'm having almost the same problem... the only difference is that the page is not a secure page...


Well, the service the page is calling is located on the same secure domain as the secure page. And in the atlas:ServiceReference Path, I specify the full secure url. It is in this service on the secure site that it calls the unsecure service. So, I would think that the browser wouldn't really know anything about the unsecure service since it's only calling a secure service. Unfortunately the unsecure service is not mine and I have no way to secure it. Is there any other type of work around for this? Thanks.

So if I understand correctly:

Your page in on the secure server. e.g.https://www.srv.com/app/page.aspx
Yes, you've got it. That's exactly how it's set up. The secure page calls a web service through Atlas on the same secure server. That service has a web reference set up to a non secure service. That's what I was afraid of, but I'm not sure then why it works if I go to the page as an unsecure url.

But where is the failure point? I assume that the call from Javascript to the secure server is correctly happening, and that it is the second call to the non-secure service that is failing?

If so, I would think this would happen without Atlas in the picture. e.g. if you make the same non-secure call from your page's Page_Load() method, does it fail in the same way?


Unfortunately because this is not on a my local box, I can't do any real step through debugging, but according to the error message, it looks like it's occurring in the atlas javascript call to the 1st (secure) service in atlas.js, line 3210, _requestor.open('POST', _effectiveUrl, true);.
I just tried something and found something interesting. I modified the atlas.js file and put an alert right before the line that's erroring with the url of the service it's trying to call. Even though I setup the serverreference path ashttps://secure..., when it alerts, it's coming back ashttp://secure... When I view source, the reference is still there as https, so I'm not sure why atlas is treating it as http. Maybe I'll have to just redo this in traditional ajax and forgo the Atlas handling.

Monday, March 26, 2012

Call server side function on javascript mouseover event?

Hi, I'm very new to ajax so please forgive me if this is a stupid question:

I have a hyperlink hooked to a mouseover event and an asp server side function called Test(). I like to know if there's any way in ASP.NET AJAX to call Test() when that mouseover event fires, and how to go about hooking this up. Code samples on how to do this would be helpful.

Thanks in advance.

Hi Totenkopf,

You can do what you want to do using the new client callback feature in asp.net 2.0 :

check these articles for more info -

http://www.devx.com/webdev/Article/28451/0/page/2

http://dotnetjunkies.com/Article/E80EC96F-1C32-4855-85AE-9E30EECF13D7.dcik

For other options check this post -

http://forums.asp.net/thread/1515994.aspx


Hmm, so can this be done at all using the existing AJAX extension? What I wish to accomplish is when a user mouseover a hyperlink, have a server-side method executes which populates a repeater control (these two are within an updatepanel)

Here's an ASP.NET AJAX solution. In this example, hovering over the link does the same thing as clicking on it. (Either action triggers an async postback.) For your example, put your repeater where I have the label. I hope this helps!

<%@. Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><script runat="server"> public void click(object sender, EventArgs e) { lbl.Text = "Moused at " + DateTime.Now.ToString(); }</script><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server" /> <asp:UpdatePanel ID="up1" runat="server"> <ContentTemplate> <asp:LinkButton ID="hoverButton" runat="server" OnClick="click" onmouseover="__doPostBack(this.id, '');" Text="Mouse Over Me" /> <asp:Label ID="lbl" runat="server" /> </ContentTemplate> </asp:UpdatePanel> </form></body></html>

Using the client callback doesn't give you the triggering you need. Unfortunately this can only be forked by using a private JS method that is included when you add an UpdatePanel.

On the client side, call the following method on the hover event:
Sys.WebForms.PageRequestManager.getInstance()._doPostBack(hyperlinkClientID,"Some String Argument");

Your custom hyperlink control should implementIPostBackEventHandler.

Create anOnHover event on you custom hyperlink control that can be used for triggering an update panel to refresh.

In theRaisePostBackEvent method that you have to implemented on your control, fire the OnHover event.


or yeah you can replace Sys.WebForms.PageRequestManager.getInstance()._doPostBack(hyperlinkClientID,"Some String Argument"); with __doPostBack(hyperlinkClientID,"Some String Argument");as shown be Steve.

Furthermore I forgot to mention you would have to register your control as an asyncronous control in OnPreRender():

ScriptManager

sm =ScriptManager.GetCurrent(this.Page);
if (sm !=null) sm.RegisterAsyncPostBackControl(this);

I've tried passing in an argument to the second parameter of __doPostBack, but I keep getting a "Invalid postback or callback argument..." popup. I then tried registering the control as suggested:

protected override void OnPreRender(System.EventArgs e)
{

ScriptManager sm = ScriptManager.GetCurrent(this.Page);
if (sm != null)
sm.RegisterAsyncPostBackControl(this);
}

... but then I get "The page cannot be registered through RegisterAsyncPostBackControl or RegisterPostBackControl"

I can get the argument with Request.Params.Get("__EVENTARGUMENT")if I disable EnableEventValidation, but is there any way to get this workingwithout setting EnableEventValidation to false?

Thanks for the help again.