Solved

Making delphi communicate with a c# service

Posted on 2016-09-26
16
124 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
  • 3
  • +2
16 Comments
 
LVL 37

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 75

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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

Author Comment

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

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
 
LVL 75

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 27

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 27

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 27

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 27

Expert Comment

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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
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…

730 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