Ajax, Webmethod, PageMethod (multiple versions)

R

Rory Becker

Hi All

I have a need for an asp.net page to make a call to a server which it did
not originate from when a button is clicked.

A simple call to pass 2-3 params and return a result. I am happy to use an
asynchronous model to do this.

I control both servers. I have been looking at Ajax and PageMethods (Ajax.Net
and Ajax Pro) and have even been looking at Calling a webservice from JS.

I need the client code for this to be as simple as possible as I am going
to have to generate it dynamically on the server side.

I looked at using pagemethods(Ajax.Net) but I realised that the page that
has to generate the calling code is not the page which willl be recieving
the call.

Should I call back to site 1 using pagemethods and then call out on the server
side to the Site2?

What is the single simplest way I can do this?

Thanks in advance
 
M

Michael Nemtsev [MVP]

Hello Rory,

not quite understood the following

RB> I realised that the page that has to generate the calling code is
RB> not the page which willl be recieving the call.

pagemethods allow you to call the server methods from client code.
You are using the same page to call the pagemethod and receive the result
back

---
WBR,
Michael Nemtsev [Microsoft MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo
 
R

Rory Becker

Hello Michael Nemtsev [MVP],
not quite understood the following
RB>> I realised that the page that has to generate the calling code is
RB>> not the page which willl be recieving the call.
RB>>
pagemethods allow you to call the server methods from client code.
You are using the same page to call the pagemethod and receive the
result
back


I wish to have the user visit http://site1.com/Page1.aspx

Page1.aspx needs to then, at some point, make a call to a method whose implementation
is actually at http://site2.com/Page2.aspx

I thought that Pagemethods only allowed the button which was generated in
page1 to call back to a method on page1.

Am I wrong?
 
M

Michael Nemtsev [MVP]

Hello Rory,

Ohhh. actually even if it were allowed to do this, I'd strongly don't recommed
you to do this, because it's gonna be mess.
You need to divide these domain areas. And I consider that incorporating
all specific loging into web Service will be the best case for you.

---
WBR,
Michael Nemtsev [Microsoft MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo


RB> Hello Michael Nemtsev [MVP],
RB> RB>>> I realised that the page that has to generate the calling code is
RB>>> not the page which willl be recieving the call.
RB>>> RB> I wish to have the user visit http://site1.com/Page1.aspx
RB>
RB> Page1.aspx needs to then, at some point, make a call to a method
RB> whose implementation is actually at http://site2.com/Page2.aspx
RB>
RB> I thought that Pagemethods only allowed the button which was
RB> generated in page1 to call back to a method on page1.
RB>
RB> Am I wrong?
RB>
RB> --
RB> Ror
 
R

Rory Becker

Hello Michael Nemtsev [MVP],
Hello Rory,

Ohhh. actually even if it were allowed to do this, I'd strongly don't
recommed
you to do this, because it's gonna be mess.
You need to divide these domain areas. And I consider that
incorporating
all specific loging into web Service will be the best case for you.

Ok I'm stil a little confused.

are you suggesting

1.> Pagemethod call from Page to Site1 which calls a webservice hosted on
Site2?

2.> Page uses webservice hosted on Site 2 directly?

3.> Something else I didn't think of ?

Thanks for your help in this
 
S

Steven Cheng [MSFT]

Hi Rory,

As for the webservice on another web application(you want to call in
originate page), is it under the same website or the same main domain
address? For client-side scirpt, we can make webrequests call to other
application, but it has limitation that we cannot perform cross domain
webrequests. If this is not a problem and what you want to do is just a
simple request with some parameters and a return value, I think you can
even use an httphandler on the remote application and let your original
application call that httphandler via xmlhttp post request:

#Use the XMLHttpRequest Object to Post Data
http://www.devx.com/DevX/Tip/17500

I also found the the following web article which mentioned some info about
calling remote AJAX webservice:

#JSON in ASP.NET Ajax: Part 2. Calling a remote JSON Web Service from
client script
http://geekswithblogs.net/JuanDoNeblo/archive/2007/10/24/json_in_aspnetajax_
part2.aspx

In addition, for the worst case that the above approaches not work, you can
still consider make a call AJAX webservice call(to the same page's
pagemethod) and let it do a server-side remote call or directly access the
server-side resource. How do you think?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
Date: Fri, 25 Jul 2008 16:47:51 +0000 (UTC)
Message-ID: <[email protected]>
From: Rory Becker <[email protected]>
Subject: Re: Ajax, Webmethod, PageMethod (multiple versions)
 
S

Steven Cheng [MSFT]

Hi Rory,

Any progress on this issue or still need any help?

Sincerely,

Steven Cheng
Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
=============================================

----------------------------------------------------------------------------
-----------
Content-Transfer-Encoding: 7bit
From: (e-mail address removed) (Steven Cheng [MSFT])
Organization: Microsoft
Date: Mon, 28 Jul 2008 04:25:22 GMT
Subject: Re: Ajax, Webmethod, PageMethod (multiple versions)
 
R

Rory Becker

Hello Steven Cheng [MSFT],
Any progress on this issue or still need any help?

My appologies for not getting back to the list on my conclusions here.

I have gone with a solution in volving the implementation of ICallbackEventHandler
in a control which I place on the form on Site1

In the handler for this I then contact Site2 behind the scenes.

In this way I do not risk exposure of fairly critical security info which
I realised needs to be passed by the call.
I am finding that this solution works very well indeed and also allows me
to move the control to other pages with relative ease.

Thanks to all for help in this matter.
 
S

Steven Cheng [MSFT]

Thanks for your reply Rory,

I'm glad that you've already got it working and also thanks for sharing the
solution with us. That'll also benefit other ones dealing with the same
scenario.

Sincerely,

Steven Cheng
Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
Date: Fri, 1 Aug 2008 11:42:07 +0000 (UTC)
Message-ID: <[email protected]>
From: Rory Becker <[email protected]>
Subject: Re: Ajax, Webmethod, PageMethod (multiple versions)
Hello Steven Cheng [MSFT],
Any progress on this issue or still need any help?

My appologies for not getting back to the list on my conclusions here.

I have gone with a solution in volving the implementation of ICallbackEventHandler
in a control which I place on the form on Site1

In the handler for this I then contact Site2 behind the scenes.

In this way I do not risk exposure of fairly critical security info which
I realised needs to be passed by the call.
I am finding that this solution works very well indeed and also allows me
to move the control to other pages with relative ease.

Thanks to all for help in this matter.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top