Hi I'd like to make a simple ajax program.
I'd like to send information from the client to server.
I'd like to send information from the server to client. (Like updates every so often)Seems simple right? But I can't find anything on this online. All the examples all for wpf talking to wcf. Or silverlight talking to wcf. But not AJAX talking to wcf. Especially when I'm talking about callbacks. not just client sending something to server.
Again, I'd like to do with in http. So ajax talks with full duplex to wcf service.
Can you point me to a tutorial? errr some information on how to do this? it sounds easy and there should be a sample out there. i'm hoping anyway.
BTW: does the client need to poll server in order to do this? and if so, doesn't it beat the purpos开发者_运维技巧e of using wcf? I'm thinking the client needs to poll server just so the server doesn't disconnect the client. but if that's the case why don't i just do this with .asmx.
One way to approach this is to use a RESTful service. That way your AJAX clients can talk to your wcf service and ask for resources using URI's and http verbs for the CRUD.
Here is something that should get you started: http://msdn.microsoft.com/en-us/library/bb412167.aspx
Yes, in order to get periodic updates from the server, the client will need to poll the server. There is no other way to acomplish this in web applications. The web server will never call the browser. It will only send replies to requests.
There is no feasible way to implement full duplex when using AJAX.
WCF is merely a way of exposing your services in various ways through .NET. Exposing as HTTP is only one of the common ways. So I would not say that it "beats the purpose". You will probably have to do polling since having duplex communication and open sockets with HTTP is not fully supported by all browsers. You can read more about it here:
Comet with HTTP
精彩评论