Solved

Making delphi communicate with a c# service

Posted on 2016-09-26
16
89 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 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 26

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 26

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 26

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 26

Expert Comment

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

920 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

14 Experts available now in Live!

Get 1:1 Help Now