How do I interact with a silverlight website from C++/C# - c#

i want to interact via code with a silverlight (ver. 4) website.
i need to scrape data from the silverlight object as well as click on buttons.
what would be the simple way to do this from c# ?
what would be the simple way to do this from c++ ?

There is no such thing as a "Silverlight Website". Silverlight is a client-side technology.
Perhaps you could use something like Fiddler to examine the client to server conversation as the silverlight app is used. You might then be able to emulate it in a C++ or C# application.
Otherwise you will need some scriptable UI testing tool perhaps.

I doubt that you can scrape any data from the Silverlight control directly. If you "view source" on the page, that's all you will be able to get by scraping the page the control runs in.
UPDATE:
Anthony makes a good point that you might be able to observe the client/server communication. Fiddler is a good tool to see what's happening in that communication. If you find that the data you need is accessible in that communication, you could modify an http proxy to intercept the traffic and pull out the data you are interested in. You would tell your web browser to go to your http proxy, and the http proxy would then connect to the internet (or your existing proxy if you use one).
There are numerous http proxies available with source code. Here's a very simple one: http://code.cheesydesign.com/?p=393

For what I gather from your very brief description of your problem I'm going to jump to the conclusion that you want to do basically what Sliverlight Spy does. Checkout this blog post describing someone trying to emulate a little of what Spy does:
http://blog.aschommer.de/page/Injecting-code-into-Silverlight-applications.aspx
He's using Fiddler to modify the binaries in the XAP as they are downloaded, but before they're loaded by the SL plug-in. Pretty complicated.
Alternatively, I wonder if there something that could be done with a hosted browser in a C++/C# application, dynamic injection of javascript into the hosted page, and the Javascript API that SL exposes.

Related

C# WPF, and data exchange with the browser

I've a C# WPF application developed in VS 2015, and I want the browser to read some data from it. Just a short string. I can save it in a text file, or in a variable but it should be visible to the browser (using JS I suppose). For instance using file:/// doesn't work if the original page is hosted online - as in my case (different source conflict). This should work in Opera and FFox, but looking at their extensions, it seems you can only develop with front-end technologies, which are not enough in my case since I use WPF to look into Win OS, and then I need to share the result with the browser.
I suspect it's possible, and no , it's not to write a malicious piece of code. For instance I can read the details of the graphic card for diagnostic purposes.
Please help, many thanks.
Browsers run in a security sandbox which is intended to stop them reading or writing files to the file system.
You could write to the user's appdata. There are various javascript frameworks which persist data to there so they can provide offline or static data.
I don't think that is a good plan though.
I suggest your first candidate would be a cookie.
Quick google on how to do that, I find:
How to create cookie in c#.net windows application?
From a web page you can use the content of a cookie dynamically. So you could change what you see in the web page after it's up and running from some process in your wpf app and do a counter or whatever.
I've not used this with windows apps and a browser but I have with a web app and Silverlight. I'm afraid I don't have that code to hand though.

Listening for http requests in a windows forms application

I've got to write a .net windows forms application that will open a webpage and then be able to react to the user clicking on certain links on the webpage. The specification I've been given has the links on the webpage just being http links.
Is there a way for my .net application to have a minimal web server on it which will allow it to handle http requests on a given port?
Use an HttpListener.
http://msdn.microsoft.com/en-us/library/system.net.httplistener.aspx
If all you need is to show a webpage, and you don't have any restrictions on the browser used, then the WebBrowser control will do the trick.
Drag it on to your form
Set the Url property to the page you need to display
Attach to the Navigating event
You can now respond to clicks, cancel them, do whatever you like. If it's just responding to client-side clicks you need, you don't need a web server. If you DO need a webserver, WinForms shouldn't have anything to do with it.
webBrowser1.Navigating += new WebBrowserNavigatingEventHandler(webBrowser1_Navigating);
private void webBrowser1_Navigating(object sender,
WebBrowserNavigatingEventArgs e)
{
//Do your thing... maybe set e.Cancel if you don't to navigate
}
Please look at the WebBrowser control and specifically the "ObjectForScripting" property. If you set it to the parent form you can actually handle javascript events from the page loaded in the webbrowser in your c# code!!!
I hope that helps!
There are different ways to do this depending on what functionality you need. If all you need to do is respond to click events, and you don't need "full" http protocol support, you can just open a socket and parse what comes in from the browser.
Alternatively, you can use HttpListener, which takes care of the http protocol parsing for you and is relatively easy to use. For what I think you need, this is probably the preferred approach. Simple, non-compiling example here: https://gist.github.com/1770645.
The "holy grail" is hosting the ASP.NET runtime in your windows forms application. I've done this and it is pretty involved. The runtime has to be hosted in a separate AppDomain, so you end up jumping through a lot of hoops to get everything running and hooked up. It also involves writing an implementation of HttpWorkerRequest that is more full featured that the framework provided SimpleWorkerRequest. Incidentally, this also works for windows services, which gives you a great way to provide service management and monitoring through a browser without having a dependency on IIS.
I have interpreted the question differently to other users, so maybe I am way off but, I read it as he is trying to render web pages from the web and react to a user clicking on a link within the web page.
The only way I can think of doing this is by using some form of renderer ie webkit and hooking into that to intercept the clicks a user makes.
You can use Nancy
Site of project: https://www.codeproject.com/Articles/694907/Embed-a-web-server-in-a-windows-service

How can I publish a web page from a Windows Forms application? (C#)

I wish to build a Windows application that will generally run in the background, but have a configurable front-end Windows Forms GUI. I also would like this program to publish a small web page which can be accessed from other machines/devices and interact or call functions of the server application.
I'd rather not deploy a full-fledged ASP.NET web site with IIS, etc. I just need something simple.
So how would I go about doing this?
Take a look at Kayak. It's a relatively small and lightweight HTTP server that you can embed into your application and should provide all the functionality you're looking for.
FWIW, I am in no way associated with this project.
Maybe it's just because i've been doing asp dev for years, but I really think you should go the iis asp route as its very simple and built into windows. I can't imagine a more straightforward way of serving a webpage that has c# behind it to programmatically effect the host system.
Thanks to Kev in the comments on my question, he pointed me to this question, in which I found a link to a lightweight C# HTTP server component I could just drop in to my application: http://webserver.codeplex.com/
Works well for little stuff like I was doing.

How to create a login mechanism with ASP.NET and client side application

I'm in the process of designing an iPhone app and I need to create a login mechanism written in ASP.NET on the server. Any ideas how the best way to go about doing this would be?
We would need to be able to create a username/ pass, login, then send a (small) amount of information back and forth from user application to server.
This is one of the more "packaged" (I guess is a good word) parts of ASP.NET, but it sounds like you would do great w/ the provided ASP.NET login controls: http://msdn.microsoft.com/en-us/library/ms178329.aspx
This gets you pretty far for free (metaphorically) and if you need more later, the MembershipProvider support is pretty rock solid.
I'm assuming that by iPhone app you are referring to a native (Objective-C) application. If this is the case then I would probably look at creating a web service (WCF) to interact with the server rather than a web site. The service would allow you to use the native widgets without having to scrape (or manipulate) a DOM object to perform a post back.
Note that there's no reason why a well written web service couldn't also be exposed as a web site if the software follows good design principles. As #Rikon mentioned the MembershipProvider support provides a good quick out of the box experience although it's easy to out grow what it provides.

How to implement a SOAP client in C# (specifically for Windows Mobile)?

I'm really confused about how to create a SOAP client in C# using .NET. I have found this page which looks really promising, but for the life of me I can't find Microsoft.Web.Services2. Also most information I find about SOAP with C#/.NET are about creating web services in ASP.NET and that's not what I want to do.
Basically what I want to do is implement a SOAP client in C# in a Windows Mobile application.
Download the old OpenNETCF.Web.Services2 source code (in the deprecated source downloads at the bottom of the page). Depending on your exact needs, this will probably provide the WSE classes you need.

Categories

Resources