Solved

Making delphi communicate with a c# service

Posted on 2016-09-26
16
71 Views
Last Modified: 2016-09-30
Hi, I have developed over the years a software using Delphi.   I need to add a function which can only be programmed using c#, this function would basically receive a command, process some DATA and return a result.

My idea was to build a c# service which would be always loaded on a server (or the workstation itself) and somehow making request to this service from my delphi application.

I know a little about REST, I'm not sure if this could be a possible solution, what I like is that I send a JSON and get the answer via a IP adress, that could be good but I'm not sure how to create a REST server and if I can use c# code to read the JSON, get the info and send back the result to my delphi app.

I could also write in a SQL database when I wan't the service to return DATA but since the c# part is going to be called a lot, I fear that this could make too much traffic on the network.

In short, I need help to find a solution to make a request to a running c# software from delphi with some parameters and read a result.
0
Comment
Question by:Buropro-Citation
  • 7
  • 4
  • 3
  • +2
16 Comments
 
LVL 36

Expert Comment

by:Geert Gruwez
ID: 41816048
only be programmed in c# ?
i'll try not go dig into those details as some messed up stuff may come up ... grin

there is extensive page on Delphi and rest here :
http://docwiki.embarcadero.com/RADStudio/Berlin/en/REST_Client_Library
0
 

Author Comment

by:Buropro-Citation
ID: 41816100
Yes indeed, long story as to why I have no choice but to use c#.    I have looked at the web page, it seems to focus on how to use REST and what it is, this is nice but I'm already familiar with using REST from my delphi app, what I'm looking for is how to actually build my own REST service using c# and to know if I can use c# code to process the information needed before returning it.
0
 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 41816347
Have you looked at OWIN self-hosting via Katana, yet? You could run a console application or Windows service on the host machine if you'd rather not use full-fledged IIS for hosting.
0
 

Author Comment

by:Buropro-Citation
ID: 41816583
Can this be installed on visual studio 2010?
0
 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 41816610
Uncertain. I believe so, since it's done via NuGet; however, there might be dependencies on a the newer versions of the Framework (4.5, I believe), and I don't recall how high 2010 supports.
0
 

Author Comment

by:Buropro-Citation
ID: 41816651
2010 seems to go only to 4.0, looks like I would have to buy a new visual studio to test the OWIN solutions, which looks promising at first glance.
0
 

Author Comment

by:Buropro-Citation
ID: 41816661
If someone has a solution beside REST, I'm open to all suggestions, so far this seems that best path (using OWIN).   If there's a way to access a service loaded on the workstation via Windows handle or something that would be great too I guess.
0
 
LVL 3

Expert Comment

by:lopem
ID: 41816755
I'm going just to suggest an idea that I am not sure if its a working one: some time ago I wanted to get data from a chess engine using a delphi program. For a long time I had no solution for the problem until I found a component that reads the data of a chess engine provided by a communication chess engine protocol. But in fact, the chess engine send thru the standard output the data (chess variations and move realized), and I dont have to know if this is a c#, c++ or c program. I dont really care how the external program ia sending the data. The component (for delphi) can be downloaded from the russian site: http://kladovka.net.ru/index.cgi?pid=list&rid=222).

Maybe this is a way to solve your problem.
Best wishes
Manuel

Ps. I can send part of my code if needed to understand how to use the omponent.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 41816847
...looks like I would have to buy a new visual studio...
Depends on your needs. You could always use the Community Edition to do the proof-of-concept, if your shop is small enough to meet the requirements.
0
 
LVL 25

Expert Comment

by:Sinisa Vuk
ID: 41818845
One way could be using SOAP .... but on the other hand - is it easy to implement simple tcpip client/server - with custom packets (could be xml,json,...). On Delphi side can be Indy and on C# side - TcpListener or similar... I do similar job but in opposite way (c# -> Delphi)
0
 

Author Comment

by:Buropro-Citation
ID: 41820512
Problem with the IP listener, the communication seems to be one way from what I can see, I can't send data and read a response at the same time like SOAP or REST enable me to do, am I correct in assuming this?
0
 
LVL 25

Expert Comment

by:Sinisa Vuk
ID: 41820680
No. Even soap and rest cannot "communicate" at the "same" time. They need to send request first, then receive a response. Tcpip client/server is lower technology behind soap and rest.  So, your ip listener is able to communicate same way....
0
 

Author Comment

by:Buropro-Citation
ID: 41820740
With REST, I would indeed have to wait for the reply when using idhttp.post.   Would I be able to do the same with the iplistener, which is to send a request and get the answer in one command?
0
 
LVL 25

Expert Comment

by:Sinisa Vuk
ID: 41821670
Yes, you can do the same... When connected ... server can send data through same channel (connection) to client back....
0
 

Author Comment

by:Buropro-Citation
ID: 41821690
I would like to look into the TCP option further, I have started a test projet with IdTCPServer and the other with IdTCPClient, do you have a short sample code that shows how to make that channel you mentioned?
0
 
LVL 25

Expert Comment

by:Sinisa Vuk
ID: 41821709
To not re-invent something... here is a good example ...
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now