简体   繁体   中英

How to call an external windows application with UI by a c# application?

We have a program ( A.exe ) with GUI and a toolbar who does NLP stuff with some text. In that toolbar we have function A which transform the text by adding some xml tags. Someone here (the boss) would like that I create a Web Service calling function A . It told me about Dynamic Data Exchange (he used it few years ago), I saw something like SendMessage .

The Web Service will be used by someone over the Inte.net: sending a text and getting the result as xml . The GUI program could not be started when someone calls the WS because it is too slow, so someone sugggests to launch this A.exe once for all and the WS will ask this A.exe by sending a DDE call. I don't know how A.exe will react in case of concurrent calls.

The Web Service will:

  1. save the text file in a directory
  2. call the A.exe
  3. the A.exe will compute the text file and create the xml file
  4. the WS will loop until the xml file exist
  5. the WS will get the xml and send it as stream to the original caller

I would like to note that:

  1. DDE is old and seems to need a DDE server capable program.
  2. SendMessage is a little bit obscur as I am a Java developer.
  3. I did not try named or anonymous pipes to make that call as suggested.

Thank you.

PS: It is an heresy to build a WS calling a server-side program with UI, isn't?

The answer to this question really depends on what you are trying to accomplish. Does your function alter data coming from an external data source such as a database or are you invoking a function within an application?

I would start with the following questions.

1) What does the function of the button do? Can it's functionality be moved into a service and shared between multiple applications?

2) Can you put the functionality inside a DLL and share between two applications?

3) Do the two apps really need to communicate with one another?

If the two processes MUST communicate with one another and you merely want application A to behave in response to a message from application B, consider using named pipes for TCP/IP communication. This is simple enough in .NET and provides quick communication between processes.

UPDATE: Here is a link with info on using named pipes: http://msdn.microsoft.com/en-us/library/bb546085.aspx .

UPDATE 2: This is an update after you updated your question. Do you have access to A.exe's source code? If you do, you have two options: 1) move that logic into your service or 2) modify A.exe to accept command-line parameters so that your service can invoke the process and get back results. If you don't have source code and you can't invoke A.exe from the command-line, then there isn't much you can do other than write the process yourself in a form your web service can call.

PS You don't have to worry about concurrent calls because each server request will execute a separate process.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM