ASP.NET Web Request and Page Generation
I've only used ASP.NET once or twice in the last month to achieve a few simple tasks but I'm looking to do something a little more complex.
I want to do the following in ASP.NET and Jav开发者_开发百科ascript:
- Have a web page, e.g. Default.aspx which queries a web service
- The web service (SOAP?) returns a number of integers in JSON (e.g. 1,2,3,4,7,9)
- Javascript will then loop through all of the child div's in a wrapper div and ensure that div id 1,2,3,4,7 and 9 exist, otherwise it will remove the ones that don't exist.
I'd normally do this with a REST web service and jQuery but I understand that SOAP is preferred in ASP.NET.
I don't think SOAP is particularly "preferred" in .NET. Certainly not for what you're trying to achieve. WebMethods are particularly easy to convert into JSON services.
Have a read of this article for examples using ASP.NET Ajax. This is easily converted to jQuery.
http://msdn.microsoft.com/en-us/library/bb515101.aspx
You cannot have a SOAP web service which returns JSON. SOAP is XML. So you have to decide which protocol you use for the service. To call the normally you would add a service reference which will generate a strongly typed client proxy allowing you to directly invoke some service method and get an array of strings representing the ids. Then you don't need javascript, you could build the HTML at the server side based on the ids you have fetched from the remote service.
You certainly could use SOAP with asp.net and it may have been preferred in times past (since it was easily consumable with web references) but if you can use jQuery & a JSON service go for it.
If you can use asp.net MVC it would be even easier as it gets out of your way when it comes to the generated HTML.
精彩评论