473,320 Members | 1,955 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Windows Application talk to Web Application ??

Hi:
I'm new at ASP.net, i want windows application to send commands to an ASP.Net 2.0 Web Application to perform certain action, either the Web-Site and Windows application within the same solution or isolated.
And if they were within the same solution, how to make 2 projects communicate with each other (Windows to Web not vice versa)

The action is " Windows Application tell the Web-Site to navigate to the next image in a list of images in a folder"

So please help me with anything :-(
Thank you
Apr 21 '07 #1
13 6077
What you could do is "screen scrape" the web application for hyperlinks.
For example. If the web page contains a button whit HREF <a href="newpage.aspx?id=5>Next</a>
Then you should let your program load this page/hyperlink in a new browser window. You can use the "navigate" method in the browser control for this.
See this link for more info on the browser control:
http://ryanfarley.com/blog/archive/2004/12/23/1330.aspx
Apr 21 '07 #2
Thank you for your reply, but i want my windows application to fire the next action not the Web-Site User.
The problem is how to make Windows Application send something to an ASP.Net web application.
I don't want the Web-Site End-User navigate or do any thing, the control is from My Windows Application.
It's a uni-cast whiteboard from Windows Application to Web-Application
Apr 30 '07 #3
elmemo
30
hi. it really all depends on how "get next image" is handled in the web application server.

if you can get to the next image by changing the url, then you could do as Arnold says and just plain control the current url of the browser instance you have under your control in your windows application (by way of a browser control for example)

if the website will provide you the next image only after you push a button that actually fires some event in the ASP.NET server and then gives you the resulting html, what you need is to connect() to the web server with your windows app (system.sockets.tcpclient) then write an appropriate HTTP request, with POST data faking the fact that it's your application (and not a human) pushing the button.

I'll try to explain further: when a user clicks a button in a web page, it might be that the button just executes javascript code, or it might be that the button actually executes code in the server (it depends on how the website was designed, etc). so if your button is doing nothing but javascript code you can very easily get the next image by setting the appropriate url in the browser instance you control from your windows app. If the button is doing something in the server then you need to provide a HTTP POST request through your windows app that looks identical to the one generated when a human user clicks the button.

If you are in the second situation, I suggest you practice with program "curl", so you can easily see headers for http requests, so that you can tune the POST request you'll have to make to the web app. You will probably need to install cygwin or some other unix/linux emulator if you want to use "curl". Once you know the post request you need to make, just have your windows app make it, and have it redirect the resulting web server's response to the html of the browser instance controlled from your windows app.

Does this help?
Apr 30 '07 #4
Thank You Very much for the connection method from Windows Application to the Web-Site Application, i really understand it and i'll do my best to make it.

but i don't understand the second situation " From Web-Site to Windows Application ", can i add reference of my Windows Application to the Web-Site. so as certain event fired from the Web-Client i send the details to My Windows Application through this ref.??
May 1 '07 #5
elmemo
30
hmmm... If I understand correctly you would like to notify your windows app about events occurring in the web browser control, like (say) knowing when the user clicked on a link, and which link it was.

Maybe you can get a web browser control that has events, and you can subscribe to its events.

If your web browser control doesn't have this capability, I can't think of any procedure that would enable you to know on which link or button the user clicked, except for an "ugly" one: doing it the way search engines record your click. What they do is they rewrite links to pages so that the links point back to the search engine first, then you get redirected. (try it: go to google and search for something, then instead of clicking on a link copy its location and paste it on notepad and see what it actually reads, you'll notice the link actually points back to google, but the url has the url of the site you clicked embedded on it.

If you want to do it this way, you could for example have your application open a port and listen to it, say port 1234. You would have to asynchronously handle traffic to this port so a callback function fires when something is writing to that port, which presumably will be an HTTP request made by the web browser control. It would have to wait until the HTTP request is complete, and then your windows application can analyse what just happened and if necesary forward that HTTP request to another site.

Your windows application would have to rewrite the links on any document, so that say instead of showing a link as "http://www.thescripts.com" you would rewrite it as "http://localhost:1234?url=www%2Ethescripts%2Ecom" note that the dots have to be urlEncoded so a dot becomes the secuence %2E . What this will do is it will contact "localhost" (which is the name of your computer) at port 1234 and make an HTTP request with that url, that has the final url encoded on it. If you do this then your application would be passed the url the user wants to see, along with any POST data (which contains the values of a form the user is submitting, complete with the information that tells you which button he pressed).

This implies that the windows application has to request the page in the web browser control's behalf, but enables you to rewrite the url's of the page again so that your windows app continues to be notified of more user events.

Remark that you would have to rewrite not only anchor elements (i.e. "links"), but also the "action" attribute in the forms, so that you redirect all events to the windows application.

What do you think?
May 2 '07 #6
I Think you are very smart -:) hahahahahaha, really thank you for your thinking, but i want to show you my problem in more details in the situation (From Web-Site to Windows Application), it's about comments, if we go back to the whiteboard that was controled from My Windows Application, the presenter showing his/her slides from Windows Application and the Web-Site User See these slides automatically navigated, at any time the Web-Site User may want to send any question to the presenter to ask him/her about any matter, logically the Web-Site User enter a text this text is to be passed to the Server, then to the presenter. the problem is when the text is to be passed from the Web-Application to Windows Application (@ Server).

Thank you very much and waiting for your reply
May 2 '07 #7
elmemo
30
hi,

Ok... now that you describe your situation things are clearer to me now. I think you should look into the XMLHttpRequest object it has a wiki page here: http://en.wikipedia.org/wiki/XMLHttpRequest

Because the way you talk about messaging, it sounds to me an awful lot like google talk's implementation that comes embedded in gmail, that's the way they do it. You will like the Atlas framework (also known as ASP.NET AJAX)

Basically you can register javascript functions that run in your browser (and thus have the ability to change and update the current page you are looking at) to server-side methods. This would achieve what you are looking for: 2-way communication between your browser and the web server.

You will also love to read this page about ASP.NET client callbacks: http://dotnetjunkies.com/Article/E80...0EECF13D7.dcik

So in the end you can have messages and a controlled slideshow all in your browser. Web 2.0 style.

Hope you like those links
May 2 '07 #8
ummm, i got this, but the one more thing that helps me.

@ My Server Windows Application
public void MovetoNextSlide()
{
//What Should i Do Here to tell the Web-Site to Navigate to the Next Slide
}


@ Web Site ASP.Net Code
public void SendCommentToPresenter(string Comment)
{
//What Code Should i Put here to pass the Comment to Windows Application
}

this is the practical problem that i face
another thing i need your advice in, what's better, putting both MyWindows Application Project and My Web-Site Project within the same solution, OR make isolated 2 solutions??
May 3 '07 #9
elmemo
30
Hey, how are you?

I just put a page together for you. I mocked it up from a number of pages, especially from msdn pages, I'm sure from here it'll be easier to do things for you. What this does is it creates an ASP.NET 2.0 page where you get a textbox and a button, whenever you press the button, the text from the textbox gets sent to the server, gets processed, and then comes back.

As for a chat application like you want, you would have to adapt this code so that messages go to the presenter instead of comming back to the current page's user. (remember each user watching a asp.net application gets its own thread, so for a message comming from a user to get to another user you will have to deal with communication between threads, which you can achieve for example by having a static object that would qeue messages to the presenter and to the rest of the people).

In a serious chat app you will also have to deal with things like: how do you know when a user has been sent a message? well you'll have to keep a live connection by having a server method jam until it gets a message for your user or something like that. but at least it's a start on having 2 way communication between the app and the server.

About the slide control issue, what I would do is I would have an extra "chat" session with a unified static object that is the same for all users in the server. This chat session would not be controlled by the user, but by the page. The page would "talk" to the static object and the static object won't respond until the presenter wishes to change slide, at which point the object would send to all users at the same time a "reply" string, which will get processed by the associated javascript callback function in the client page and be treated as the next "src" attribute of an iframe html element on your page that presumably contains the current slide (and thus the slide will change)

About the windows application / webapplication solution... If I may be so bold I would suggest that you spare the windows application and just plain do it all as a web app. I think the windows application would only be justified if you need to have access to openGL within your client app. This way you would not need to worry between communication with a windows app, plus your app would be usable from anywhere.

This code uses the XMLHttp object I was talking to you about to create "side HTTP channels" where you can communicate with the others without refreshing the main page, but it does so behind the scenes so you don't have to even know about it.

I hope I was less confusing this time! Anyways here goes the code

Kind regards, memo

Expand|Select|Wrap|Line Numbers
  1. <%@ Page Language="C#" AutoEventWireup="true" %>
  2. <%@ Implements Interface="System.Web.UI.ICallbackEventHandler" %>
  3.  
  4. <script runat="server">
  5.   private string ret = "";
  6.  
  7.     protected void Page_Load(object sender, EventArgs e)
  8.     {
  9.         ClientScriptManager cm = Page.ClientScript;
  10.         string callbackRef = cm.GetCallbackEventReference(this, "argumento", "receiveServerData", "");
  11.         string clientCallbackScript = "function callServer(argumento, context) { " + callbackRef + "; }";
  12.         cm.RegisterClientScriptBlock(this.GetType(), "callServer", clientCallbackScript, true);
  13.     }
  14.  
  15.     void ICallbackEventHandler.RaiseCallbackEvent(string clientArgument)
  16.     {
  17.       ret = clientArgument;
  18.     }
  19.  
  20.     string ICallbackEventHandler.GetCallbackResult()
  21.     {
  22.         return "received '" + ret + "' alright!";
  23.     }
  24. </script>
  25.  
  26. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  27.  
  28. <html xmlns="http://www.w3.org/1999/xhtml" >
  29. <head runat="server">
  30.     <title>AJAX skunkworks</title>
  31.     <script type="text/javascript">
  32.       function receiveServerData(argument, context)
  33.       {
  34.         alert("received data");
  35.         document.getElementById("msg").innerHTML = argument;
  36.       }
  37.     </script>
  38. </head>
  39. <body>
  40.     <form id="form" runat="server">
  41.     <div>
  42.       <input type="text" value="type here" id="txtBox" />
  43.       <input type="button" value="llamar al servidor" onclick="callServer(document.getElementById('txtBox').value,alert('sending to server'));" />
  44.     </div>
  45.     <span id="msg" >Here we go</span>
  46.     </form>
  47. </body>
  48. </html>
  49.  
May 4 '07 #10
ummm, your word about converting my all application to ASP.Net Application is a good idea but i have a due date because this is a graduation project, i have got an idea to make Windows Application Talk to Web Application, can we use Windows Queues (MSMQ) we will make 2 queues, one from Windows to Web, and the other from Web to Windows. but we will use timers to read from the queue in each applications, is this powerful?
May 5 '07 #11
elmemo
30
Hi,
I have never worked with MSMQ, it certainly looks powerful. I have 2 thoughts:
1.- Doing it the message-qeue requires that you install your windows app client on all machines, and that you somehow provide these client machines with a way to reach the queue. If your clients aren't all on the same computer or domain, this might be tricky to achieve securely.
2.- If you are going to do it this way, it means you don't really care much if you imposed a restriction on your app that would only make it usable within a certain network.

That said, maybe the ASP.NET part of your application is unnecessary. You could develop an application based on a custom-made application server (with the message queue) and rich clients, but instead of presenting slides, links, and chat sessions through a web control in your app, why not do it with a dynamic windows form that could change its contents on the fly. This way, because you have a windows form instead of a web browser, you certainly have much more power for displaying content and subscribing to events that happen in your windows form. Chat sessions and real-time annotations to the slides by the app users would be possible and way, way easier to implement than through AJAX.

I think doing it with ASP.NET really only adds a layer of complexity because you have to present HTML content to the user with a web browser control, translate user action into HTTP requests, use ASP.NET to translate these HTTP requests into MSMQ messages, and then back to HTML content.

But if you still want to do it this with an ASP.NET tier, I found an interesting read for you in the web: http://www.15seconds.com/issue/031202.htm
May 6 '07 #12
I Post my topic at Microsoft MSDN forum at this link:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1563261&SiteID=1

and i got some good ideas, and i'm linking all valuable replies from here and MSDN forum , and i will do the following:
create a web service that have the Business logic, and to send certain message to the web application i'll use the HTTPRequest to faking the invoking of certain code and using Browser instance i'll broadcast this event.

i hope if someone have any advice for me please send it her thanks
May 7 '07 #13
What should I do if I wanna simmulate a button click on a web page from the windows application? Thanks in advance.

hi. it really all depends on how "get next image" is handled in the web application server.

if you can get to the next image by changing the url, then you could do as Arnold says and just plain control the current url of the browser instance you have under your control in your windows application (by way of a browser control for example)

if the website will provide you the next image only after you push a button that actually fires some event in the ASP.NET server and then gives you the resulting html, what you need is to connect() to the web server with your windows app (system.sockets.tcpclient) then write an appropriate HTTP request, with POST data faking the fact that it's your application (and not a human) pushing the button.

I'll try to explain further: when a user clicks a button in a web page, it might be that the button just executes javascript code, or it might be that the button actually executes code in the server (it depends on how the website was designed, etc). so if your button is doing nothing but javascript code you can very easily get the next image by setting the appropriate url in the browser instance you control from your windows app. If the button is doing something in the server then you need to provide a HTTP POST request through your windows app that looks identical to the one generated when a human user clicks the button.

If you are in the second situation, I suggest you practice with program "curl", so you can easily see headers for http requests, so that you can tune the POST request you'll have to make to the web app. You will probably need to install cygwin or some other unix/linux emulator if you want to use "curl". Once you know the post request you need to make, just have your windows app make it, and have it redirect the resulting web server's response to the html of the browser instance controlled from your windows app.

Does this help?
Jul 3 '07 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: piyush | last post by:
Sorry for repeated posting but I couldnt get things right/completely in the first post. I am in the process of deciding the IPC mechanisms to use for communication between 1) An application...
0
by: piyush | last post by:
Sorry for repeated posts, I couldnt get things right and complete in the previous post. I am in the process of deciding the IPC mechanisms to use for communication between 1) An application...
4
by: Kris | last post by:
I have a Windows Service in C# talking to a serial port and using Remoting. It also uses several COM objects. On customer's computer the service will occassionally hang somewhere - the service...
9
by: Justin Engelman | last post by:
Hi, I have a website that uses an ISAPI filter that will redirect anyone going to any page on the site to an SSL login page (on a different website with the same root domain) if they do not have...
4
by: Blaxer | last post by:
I have read approximately 30 articles now on various methods to make your vb.net application automatically update itself and I can't see how they apply to a vb.net windows services projects. The...
4
by: Jessica Weiner | last post by:
I have an simple application that opens up a windows form. However, whenever I run the executable, the dos window appears in the back How can I get rid of that? Thanks. Jess
2
by: shyam | last post by:
I have a C++ COM based windows service which have more than 30k lines of code and which is stablized over years. We need to take the advantage of the ..NET framework for this project, especially...
3
by: Boris | last post by:
We have a native Windows DLL (let's call it native.dll) we developed a .NET interface for (let's say managed.dll). When a .NET application now uses the ..NET interface to talk to the Windows DLL we...
4
by: Pini | last post by:
Hi all, I have a massive windows application that refernces a lot of assemblies and doing a lot of DAL anf IO operations. I want to expose this application to the interner so that a user can...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.