I am posting this as a part of my effort in searching the best possible design solution for my requirement.
I am currently working on a complex server control(not user control) in asp.net which is going to be rendered into html elements on the client side.And those html elements needs to do a ajax call backs to the server using js/jquery. Here is the problem. As this is a serverside control and can be added into any application/domain. I dont want to have those callback services hosted separately. Is there any way that I can host those server callback services in the same library? If so, how can I access them from the client side?
I've never tried putting a WebService into a ServerControl, but I know you can create a composite control (a server control that inherits form the CompositeControl class) that has an update panel in it. With that you can do server side processing with asynchronous calls from the client, similar to JQuery calling a WebService.
Related
I need to call a cross domain web service (.asmx) via a page within an asp.net application. The user will type in a search query in which the app will send off to the web service, then the page will be updated with the data.
My question is how might I do this without postbacks? As I am just trying to retrieve data rather than entering or manipulating it.
My attempted solutions:
1. Ajax via jquery -> issue: CORS is not supported.
2. serviceReference (for client side services calls) but this is only for a local (on domain) service
3. Lastly I am trying to use updatepanel where the value from a textbox is used in querying the web service however this is obviously forcing a partial postback, is there a way to have the update panel use a get req instead? If not, how might I go about doing this because I am stuck! Lastly would this solution be easier if an ASP MVC structure? I am learning. Thanks.
Create an ashx handler which queries the remote service based on parameters handed by ajax.
Use an ajax-request to the ashx handler to call your proxy via jQuery AJAX.
Or just use the Yahoo YQL proxy:
Is there a free JSON proxy server which supports CORS or JSONP?
Or if the web-service supports JSONP, you can use JSONP directly.
If you need to create a proxy yourself, here is how:
http://www.codeproject.com/Articles/25218/Fast-Scalable-Streaming-AJAX-Proxy-continuously-de
I am currently developing an IRCX AJAX Chat based system and have a few questions regarding the Server and Client implementation; Any suggestions are welcome:
Server
Should this be implemented as a Web Service, or a Windows Form application? I have experience in developing Windows Forms based servers, however I am wondering if this would be better implemented as a Web Service and if so, why?
Client
How are Web Based Clients implemented today and what is the preferred method to implement a Web Based Client?
My solution so far are
ASP.NET Web Forms with an AJAX Update Panel (This seems the most viable)
Using jQuery connecting to the web service with a JavaScript timeout
Polling
How frequently should the server be polled for new messages? 0.5 seconds seems a bit excessive and anything between 2 or 3 seconds seems sluggish.
Thanks for your input.
Have a pool of connections and maintain a sort of proxy between the server and clients that sends the data to the right client based on a session id. This would mean your chat server is protected against packet attacks and you would not have to deal with web sockets which an attacker could hijack and do what they require with it.
I know the question is old, but there's an even better approach now.
SignalR is designed for things like this (real time web functionality)
SignalR can be used to add any sort of "real-time" web functionality to your ASP.NET application. While chat is often used as an example, you can do a whole lot more. Any time a user refreshes a web page to see new data, or the page implements Ajax long polling to retrieve new data, is candidate for using SignalR.
Here's a tutorial for a basic chat application HERE.
For more information, visit the SignalR website.
I believe using ASP.NET (Sockets and an Update Panel) seems to be the best approach. Using jQuery in this context now seems a bit invalid because it would not maintain a persistent state with the Chat Server which is required for Real Time Communication.
An alternative way I found would be using a Web Sockets and Backbone.JS to deal with the data returned from the server.
http://blog.fogcreek.com/the-trello-tech-stack/
I'm developing a web site, and i'm using infragistics for web, but I want to use in some pages silverlight controls (Infragistics too). Is there a way to access a silverlight control's properties and methods from an aspx page?
Thanks in advance for the help.
The silverlight control is running on the client so the best way to access the silverlight's control data is by exposing via javascript methods.
You can map your properites and functions in your silverlight control to javascript methods and then call them as needed.
If you need access the silverlight data server side, then you should expose what you need via javascript and then call the javascript function before a postback and have it write values to a hidden field so that you can then retrieve them server side by accessing the request's posted values.
To expose your some data via javascript just create function in your silverlight page like:
[ScriptableMember]
public int GetValueFromSilverlight()
{
// lame example
return int.Parse(textBox.Value);
}
You could then call this function client side and write it's values to a hidden field which will cause it to post along with the rest of your data.
I asked a similar question a while back when I was working on a silverlight project.
Another thing you could do (which I don't recommend) is to have your silverlight control write back to the application's session or database via web services and then your server side page calls can read the data from whatever location you have written to.
The main point is your need some type of intermediate to get the data back to server so it is accessible and you want something is flexible (hidden field method was my choice).
Is it possible to set up a listener in a Silverlight control to listen for events on the hosting aspx web page? I want to have several Silverlight and ASP.NET user controls hosted in a web page. I want to fire an event on one user control, sending an event to the host page (it needs to be notified), and then I want to broadcast an event back to all controls (both Silverlight and ASP.NET) on the form. This this possible to do with Silverlight?
Silverlight is a client side technology. It can interact with the DOM and it can listen to DOM events, but it can't interact with the ASP.NET controls or listen to events from them.
Silverlight is a client-side technology. You are allowed though to call Javascript functions. Having that, you can take advantage of the ASP.NET AJAX to make calls to web methods on the host ASPX page. Even better, you can force a full post-back of the ASPX page from Javascript.
(sorry for the late response. i've just come accross this when looking for something else)
In the WCF application that I am working on, I need to access the generated source of a particular webpage (after all the AJAX calls on the page are made).
I have tried using System.Net.WebRequest but it just brings me back the original source of the page. Is there a way to execute a page and then get the source?
Else, is there a way to execute Javascript from within a WCF service? I could use the javascript and JSON response to create the HTML page from within my webservice then!
You could use Javascript to traverse and pass the DOM than make a call into your WCF service from the Javascript when all the Ajax calls are complete. If you are after the data that is stored on the page after all the Ajax calls I would re-think your implementation...
Petar
Well, WCF is designed to be consumed by non-browsers, so there really is no way to expect that a WCF response can contain Javascript that will be automatically executed by the client.
#Petar: Thanks for your input. Yes, I am after that data that will be stored in the page after the Ajax calls. And, somehow the third party vendor will not give me that data via some JSON calls which I could directly call from my own WCF service.