How can I develop a DLL IN Xbase++ to use it in a C# program

This forum is for eXpress++ general support.
Message
Author
k-insis
Posts: 100
Joined: Fri Jan 28, 2011 4:07 am

Re: How can I develop a DLL IN Xbase++ to use it in a C# program

#11 Post by k-insis »

> I am now aware that the only way to interact with Alaska Xbase++ DLL libraries is through a REST API.

Actually you can do this with SOAP and direct socket connection too.

Bonus is that you can put that small server side program to server and all PCs with network access can request it.

On SOAP you will heve to publish WSDL and add XSD for data validation. REST is more lax here and does not need such things.

Direct TCP/IP socket is lowest level connection .

Once you have such REST server just about any programming environment can connect to it and work with it.


Diego Euri Almanzar wrote: Thu Apr 18, 2024 12:24 am Auge_ohr, totally agree.

SlavkoDam: I was watching the programs you indicated to me. It's super interesting, I really appreciate the help. Thanks to the help of all of you, I am now aware that the only way to interact with Alaska Xbase++ DLL libraries is through a REST API.

Although, when studying the indicated source programs, I still do not understand why two executables are formed: HTTPSERVICE.EXE and HTTPCTR.EXE

I still don't understand what the relationship is between the two, nor do I understand how to form the endpoint URLs, or the controls, that a REST API should have. Since, obviously, access to a REST API is through a URL.

Of course, the idea is great, I just have to continue studying the case, or continue looking for a more illustrative example than Alaska Xbase++.

Finally, you would also have to learn how to publish the REST API. It would be necessary to investigate whether it is through IIS, or as a service installed on the computer.

Best regards.

Diego Euri Almanzar
Posts: 167
Joined: Thu Nov 05, 2020 10:51 am
Location: DOMINICAN REPUBLIC

Re: How can I develop a DLL IN Xbase++ to use it in a C# program

#12 Post by Diego Euri Almanzar »

SlavkoDam, excellent information. And since REST APIs are so widely used, it would be interesting if you could provide us with an example with your excellent library, which I bought and find great.

Can you attach a simple example with a single endpoint, or a single URL?
I will be thankful.

K-insis, I was looking in the Alaska Xbase++ documentation on how to develop a Webservice, or REST API, but I didn't find anything, not even with SOAP technology.

I would appreciate it if you could provide me with an example.

Best regards.

User avatar
Tom
Posts: 1171
Joined: Thu Jan 28, 2010 12:59 am
Location: Berlin, Germany

Re: How can I develop a DLL IN Xbase++ to use it in a C# program

#13 Post by Tom »

On SOAP you will heve to publish WSDL and add XSD for data validation. REST is more lax here and does not need such things.
You don't have to. The service itself does not need it.
Best regards,
Tom

"Did I offend you?"
"No."
"Okay, give me a second chance."

k-insis
Posts: 100
Joined: Fri Jan 28, 2011 4:07 am

Re: How can I develop a DLL IN Xbase++ to use it in a C# program

#14 Post by k-insis »

> K-insis, I was looking in the Alaska Xbase++ documentation on how to develop a Webservice, or REST API, but I didn't find anything, not even with SOAP technology.

You will have to get in touch with Alaska for that, imho they are historically too 'tight' on shipping complete time relevant samples

Mr Donnay does provide a starting point for stuff at: /Express/Samples/Web20 so you should start there to get into web ; If REST is too hard, you can always use good old POST which will do just as fine for communication.

Also read what Mr. Slavoljub wrote and at last


Personally I use xb2net libraries which support SOAP and RESTful clients & you can write own server (:FilterRequest). Check www.xb2.net , Mr Borzic provides demo with source samples for many scenarios. Works fast and stable, can be run with current WINE toolkit on linux servers too.

Diego Euri Almanzar wrote: Thu Apr 18, 2024 8:37 pm SlavkoDam, excellent information. And since REST APIs are so widely used, it would be interesting if you could provide us with an example with your excellent library, which I bought and find great.

Can you attach a simple example with a single endpoint, or a single URL?
I will be thankful.

K-insis, I was looking in the Alaska Xbase++ documentation on how to develop a Webservice, or REST API, but I didn't find anything, not even with SOAP technology.

I would appreciate it if you could provide me with an example.

Best regards.


User avatar
SlavkoDam
Posts: 86
Joined: Wed Apr 27, 2022 10:12 am
Location: Negotin, Serbia
Contact:

Re: How can I develop a DLL IN Xbase++ to use it in a C# program

#16 Post by SlavkoDam »

Diego,

Here is a simple example for HTTP server and HTTP client. This is the code for HTTP server application. Endpoint URL is function GetCust(). In your future project, URLs will be functions in your DLL.

Code: Select all

PROCEDURE Main
oSrv = HTTPSRV(,1024,,,.F.)
RETURN

FUNCTION GetCust(oSrv)
RETURN GetCust_(VAL(HAPARVALS(oSrv)[1]))

FUNCTION GetCust_(custid)
**
LOCAL fld_cnt,reply,I, sep := chrCRLF
**
IF VALTYPE(custid) == "C"
  custid = VAL(custid)
  sep = "<BR>" + chrCRLF
ENDIF
USE Customer INDEX Custno NEW
IF DBSEEK(custid)
  fld_cnt = FCOUNT()
  reply = ""
  FOR I=1 TO fld_cnt
    reply += FIELDNAME(I) + ":  " + TRIM(VAL2STR(FIELDGET(I))) +;
             IF(I < fld_cnt,sep,"")
  NEXT
ELSE
  reply = "No customer id."
ENDIF
CLOSE
RETURN reply
This is the code for HTTP client application.

Code: Select all

PROCEDURE Main
...
oCln = HTTPCLN(,1024)
Xcustid = 10
cust = HTTPGET(oCln, "GetCust", {{"cid",Xcustid}})     // Call server URL GetCust() with Xcustid argument
MSGBOX(cust)
...
RETURN         
There is no need to create HTTP request, HTTP response, HTTP headers, etc. This is all done automatically by HttpSrv() and HttpCln() functions. You don't have to create WebHandler as in Alaska or RESTHandler as in Cris BOA, it is integrated in HttpSrv() function. Your server and client application codes will be simple, compact and straightforward.
Last edited by SlavkoDam on Mon Apr 22, 2024 10:25 pm, edited 1 time in total.
Best regards,

Slavoljub Damnjanovic
SD-SoftDesign, Alaska Software Technology Partner
https://www.sd-softdesign.com
https://www.sd-softdesign.rs

User avatar
SlavkoDam
Posts: 86
Joined: Wed Apr 27, 2022 10:12 am
Location: Negotin, Serbia
Contact:

Re: How can I develop a DLL IN Xbase++ to use it in a C# program

#17 Post by SlavkoDam »

A similar scenario can be applied to a WebSocket connection, using WSSRV() and WSCLN() functions. And there is one more option, WebSocket client could be both desktop and web client.

Here is a simple example for WebSoscket server and WebSocket client. This is the code for WebSocket server application. Endpoint URL is function GetCust().

Code: Select all

PROCEDURE Main
oSrv = WSSRV(,1024,,{,,"GetCust"})
RETURN

FUNCTION GetCust(oSrv,msg)
RETURN GetCust_(msg)

FUNCTION GetCust_(custid)
**
LOCAL fld_cnt,reply,I, sep := chrCRLF
**
IF VALTYPE(custid) == "C"
  custid = VAL(custid)
  sep = "<BR>" + chrCRLF
ENDIF
USE Customer INDEX Custno NEW
IF DBSEEK(custid)
  fld_cnt = FCOUNT()
  reply = ""
  FOR I=1 TO fld_cnt
    reply += FIELDNAME(I) + ":  " + TRIM(VAL2STR(FIELDGET(I))) +;
             IF(I < fld_cnt,sep,"")
  NEXT
ELSE
  reply = "No customer id."
ENDIF
CLOSE
RETURN reply
This is the code for WebSocket desktop client application.

Code: Select all

PROCEDURE Main
...
oCln = WSCLN(,1024,,,{,,"DispCust"})
Xcustid = 10
WSSEND(oCln,LTRIM(STR(Xcustid))     // Call server URL GetCust() with Xcustid argument
...
RETURN

FUNCTION DispCust(oCln,msg)
**
MSGBOX(STRTRAN(msg,"<BR>",""))
RETURN NIL    
This is the code for WebSocket web client. Put it in a file "customer.htm" and start it in the Internet browser.

Code: Select all

<!DOCTYPE HTML>
<html>
<head>
<title>Customer web socket client</title>
<script type="text/javascript">
var url = "ws://localhost:1024/", sck = null, all = document.all;

function WsOpen()
{ if (typeof(WebSocket) !== "function")
    { all.Status.innerHTML = "Not supported";
      return;}
  if (sck == null)
    { sck = new WebSocket(url);
      all.Status.innerHTML = "";
      sck.onopen = function(evt)
        { all.CustID.value = 0;            
          all.Cust.innerHTML = "";
          all.Status.innerHTML = "Opened"; };
      sck.onclose = function(evt)
        { all.CustID.value = 0;
          all.Cust.innerHTML = "";
          all.Status.innerHTML = "Closed"; };
      sck.onmessage = function(evt)
        { if (typeof(evt.data) == "string") 
            all.Cust.innerHTML = evt.data; }; }
}
      
function WsClose() 
{ if (sck !== null)
    { sck.close();
      sck = null; }
}
        
function WsSend(text)
{ if (sck !== null && sck.readyState == WebSocket.OPEN) sck.send(text); }
</script>
<style>
button {width:80px}
</style>
</head>

<body>
<br>
<button onclick="WsOpen();">Open</button>
<button onclick="WsClose();">Close</button>
<br><br>
Status: <span id="Status" style="margin-left:10px; color:blue"></span>
<br><br>
<label>Customer ID (1-22): </label>
<input id="CustID" size="2" maxlength="2" value="0" style="margin-left:10px" onchange="WsSend(all.CustID.value);"></input>
<br>
<p id="Cust"></p>
</body>
</html>
Again, everything is done automatically by WSSRV() and WSCLN() functions.
Last edited by SlavkoDam on Mon Apr 22, 2024 10:31 pm, edited 5 times in total.
Best regards,

Slavoljub Damnjanovic
SD-SoftDesign, Alaska Software Technology Partner
https://www.sd-softdesign.com
https://www.sd-softdesign.rs

Diego Euri Almanzar
Posts: 167
Joined: Thu Nov 05, 2020 10:51 am
Location: DOMINICAN REPUBLIC

Re: How can I develop a DLL IN Xbase++ to use it in a C# program

#18 Post by Diego Euri Almanzar »

SlavkoDam, K-inisis

Excellent explanations and examples. I am very grateful to you.

Best regards.

k-insis
Posts: 100
Joined: Fri Jan 28, 2011 4:07 am

Re: How can I develop a DLL IN Xbase++ to use it in a C# program

#19 Post by k-insis »

- So if you need to expose services and data to outside programmers use REST and document everything. Start with small, then expand.

- For internal only, use as direct as possible approach.

And 1,2,3 you will have proper three-tier system.

Oh and always consider good network security practices.

Diego Euri Almanzar wrote: Fri Apr 19, 2024 9:13 pm SlavkoDam, K-inisis

Excellent explanations and examples. I am very grateful to you.

Best regards.

Diego Euri Almanzar
Posts: 167
Joined: Thu Nov 05, 2020 10:51 am
Location: DOMINICAN REPUBLIC

Re: How can I develop a DLL IN Xbase++ to use it in a C# program

#20 Post by Diego Euri Almanzar »

K-insis, very good recommendation. You are very right.

At the moment, I'm only looking to get from a C# application to the functions that I develop in Xbase++
That would allow me to not have to rewrite much of the source code in C#. If the API works, I'll save a lot of time.

And, since it is only to interpret functions, or DLLs, made in Xbase++, I don't think it is necessary to expose yourself with HTTPS. With an HTTP on port 81, it is more than enough.

Very thankful,

Best regards.

Post Reply