Getting Generated HTML in a WCF service - c#

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.

Related

Calling web service without using a post back

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

C# Basic web HttpWebRequest, does not support Javascript

I have a basic C# HttpWebRequest. My problem is the page that it is sending the GET request to, requires javascript (on the client-side) to be enabled for the content to generate.
How can I add javascript support to my code? Is it even possible?
The server can't really know whether the client supports Javascript. It can only go on the data you give it.
So there are two possibilities:
It's using headers to work out what response to send, and inferring that you can't run Javascript. Solution: work out what headers it requires, and set them explicitly.
It's sending you back the page, but you're unable to use it because you're not displaying it on a browser. Solution: look at the page, work out what AJAX calls the Javascript is making, and make those instead. You may not even need to fetch the original hosting page.
HttpWebRequest just implements GET, you need full browser to execute JavaScript (and possibly need CSS files to as scripts may depend on them).
The built in approach is to use WebBrowser control to render pages, that grab innerHTML after you find that JavaScript rendering is done.

recommended way to handle this case in .NET for web application

I am relatively new to web development and am trying to figure out what would be the recommended way to deal with my current situation.
All of this needs to be in the .NET framework.This is a very simple use case, but I am required to deal with a bigger problem here.
Here is the flow of things:
Client clicks a button on a page: "Calculate Sum"
This invokes a call to the webservice which calculates the sum and returns some extra info on how to render it on the html page
The client receives this info from the webservice and populates one of the variables in the javascript that is used in the resulting page and the extra info is used to render the html page
The resulting page would have a button; when clicked would redirect to a third party application. It would then process this request and send a POST back to one the URLs I have specified. I am then required to consume the info (string) that they would send back.
Let me know if I am not clear in any of this and if you want me to specify more info. This is more about learning on the job and so I am trying to find out the best way to solve this problem.
Thanks
It sounds like, if as you say everything must be in .NET framework, then you can use Visual Studios to develop this project in VB or C#. Essentially, the page that initially sends the request to the web service would be built as a .aspx webpage. Then you can build a web service in C# or VB .asmx which handles the calculation, returns a result that is parsed by javascript on another asp.net web page and produces a button to send the gathered data as a POST to another URL.

Server control library calling its own services

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.

How to access a silverlight control's properties and methods from an aspx page?

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).

Categories

Resources