0

I am a C# developer and the requirement is to call Java application programmatically with C# and I should be able to get access (read/write) to the controls of Java application.

For example, suppose there is a Java application that searches for a product by entering the product name in the search textbox and then by hitting "GO" button. I have to do the steps programmatically with C# (WinForm) application.

The 3rd party executable could be developed either in Java or in .NET.

Please provide me with the solutions/guidelines.

Thanks in advance!

Shadow The GPT Wizard
  • 66,030
  • 26
  • 140
  • 208
  • 5
    Hello and welcome to StackOverflow! What have you tried so far? What worked? What didn't? (This is not a "give me a complete solution" type of site; we will *help* you, but not *do your work for you*. There is a difference.) – Piskvor left the building Jan 11 '12 at 09:08
  • I have tried to load the Java application with the Process class but I am not able to find a way to extract/get access to the controls from the Java executable. – Vikas Anand Jan 11 '12 at 09:36
  • Possibly a question for programmers (http:\\programmers.stackexchange.com) SO site? – Alexander Galkin Jan 11 '12 at 09:39
  • @VikasAnand Can you not just invoke a new process from C# application? i.e. Process.Start("JavaAppName.exe") – AksharRoop Jan 11 '12 at 10:02

1 Answers1

0

If you must make applications interact this way, your safest bet would be to use the interop with Windows API to send the target application messages and/or gain limited access to data within its controls. If you don't have a C/C++/VC/Win32 background, this can be a challenging task. You would need to familiarize yourself with the windows api, structures, etc.

I could certainly point you to some helpful resources but please note that this is not a recommended approach for many reasons (including security and stability) and should never be used in a production scenario.

EDIT

If you do not have access to the source code of the target applications, and these applications do not provide an API, the term inter-process communication does not apply here. You would essentially be hacking your way into these applications and should be aware of the implications.

Since you have not developed these applications, have a look at at this link. As explained in my answer, you could inspect the target application using a tool like Spy++ to figure out the control hierarchy. You can then use Win API to send messages to the control. It does not matter whether the target application is built in .NET, Jave or C.

In case of web applications, whether running on the local machine or outside, you can scrape data from existing pages and you can post data from within your application. Have a look at the string DownloadString (string address) and byte[] UploadValues (string address, string method, NameValueCollection data) methods of the System.Net.WebClient class.

Raheel Khan
  • 14,205
  • 13
  • 80
  • 168
  • http://stackoverflow.com/questions/8699950/csharp-to-java-jni-porting-call-to-run-on-ubuntu follow this thing – Arunkumar Chandrasekaran Jan 13 '12 at 11:35
  • Ok...but it is the requirement of my client and so it is the main concern for this project. I have googled and found that WCF could be a good choice for inter-process communication between two or more applications running in their own processes. So please suggest me on this. Also, the applications that will run in background could be either Windows application, Java application, or Web application. – Vikas Anand Jan 13 '12 at 12:36
  • And these background application will be accessed through a WinForm application. The foreground application can read/write data within the background applications and also can trigger events such as button click of the background applications. – Vikas Anand Jan 13 '12 at 12:43
  • Since you have not developed these applications, have a look at at [this](http://stackoverflow.com/questions/3288092/access-is-denied-when-trying-to-get-the-url-text-from-address-bars-handle) link. As explained in my answer, you could inspect the target application using a tool like Spy++ to figure out the control hierarchy. You can then use Win API to send messages to the control. – Raheel Khan Jan 13 '12 at 14:30