I'm trying to find an easy way to send a string (in my case JSON) from VBA data provider to C# server.
My Server already has a high level communication between server and client. In my case I use CORBA IIOP.NET, but I can easily change it to WCF.
My question is: How can I send a string to my C# Server?
From my C# server I got the code from Code Project (not tested)
public void Server()
{
//start server
TcpListener tcpServerListener = new TcpListener(6666);
tcpServerListener.Start();
//block tcplistener to accept incoming connection
Socket serverSocket = tcpServerListener.AcceptSocket();
//open network stream on accepted socket
NetworkStream serverSockStream = new NetworkStream(serverSocket);
StreamReader serverStreamReader = new StreamReader(serverSockStream);
Console.writeLine(serverStreamReader.ReadeLine());
}
I'm having dificult to send the string via VBA. Can anyone help me with that.
PS: To parse JSON in C# I'm using JSON.NET and VBA I'm using VB JSON
Now I see that we can't ask for good practice and ideias to help in VBA, Excel-VBA tags. So I did my research and made my choices. Let me know if someone has a better ideia to do this remote integration.
My example has three tests. One server (C#) and two clients (C# and VBA) that can be seen bellow.
I use the ideia of Store and Company just to exemplify JSON for .NET works well with inheritance. Here is my classes:
My C# client just create two
Stores
serialize and send it to Server usingTcpClient
.Code:
My VBA client is a slightly different. But it's the same ideia
Code:
Finally my server that is really simple. It just listen a port and when a message come it deserialize JSON:
Note that I use
TcpClient
for VBA. Thanks rory - code bellow:I hope that it can be usefull for someone.