-
Jul 11th, 2022, 08:49 AM
#1
Thread Starter
Hyperactive Member
Need help with GUI for Service application
Hi guys,
I built a Service application that connects to a server, and is working great.
But I want some way to control the Service (change config, start, stop, restart etc...)
On the Client side, I'm thinking for just a NotifyIcon, and to be able to open Forms (as popups).
But on the Server side I want a WinForm.
I searched all over, every thread starts with "Pre Windows Vista it's not a problem..." then something with Session0, but no real solution...
I do want the service to run in Session0 (run on boot), but I also want a way to control it from the user...
What is the best way to go about this?
Thanks
Last edited by threeeye; Jul 11th, 2022 at 09:07 AM.
-
Jul 11th, 2022, 11:01 AM
#2
Re: Need help with GUI for Service application
You will need a way to communicate with the service app. Many ways to accomplish, I'm sure...
I've used HTTP listeners to communicate between service apps and UI apps.
You could go primitive and drop text files in some folder and have the service app "file watch" for those.
Use a database in the middle, could also be an option,
-
Jul 11th, 2022, 11:10 AM
#3
Re: Need help with GUI for Service application
Or WebAPI.
I've used it lately. It's a sh$t sandwich at first but I can say I find it more easy to manipulate than the aforementioned solution. No offense on our brilliant tech of course.
Just not that it runs on IIS, if you want to have a form on the server (why?) then it won't do. Btw, a form on the server?I would much rather prefer a forms on the client of a form app that manipulate server data than a form on the server. Especially if many people use the server, the form can be opened, closed, removed etc.
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
Jul 11th, 2022, 11:52 AM
#4
Thread Starter
Hyperactive Member
Re: Need help with GUI for Service application
Originally Posted by szlamany
You will need a way to communicate with the service app. Many ways to accomplish, I'm sure...
I've used HTTP listeners to communicate between service apps and UI apps.
You could go primitive and drop text files in some folder and have the service app "file watch" for those.
Use a database in the middle, could also be an option,
HTTP listener sounds good, I'm using TCP listener in my service to communicate with the server, is it the same thing?
I don't want to do it the "dirty" way (with a text file)...
Originally Posted by sapator
Or WebAPI.
I've used it lately. It's a sh$t sandwich at first but I can say I find it more easy to manipulate than the aforementioned solution. No offense on our brilliant tech of course.
Just not that it runs on IIS, if you want to have a form on the server (why?) then it won't do. Btw, a form on the server?I would much rather prefer a forms on the client of a form app that manipulate server data than a form on the server. Especially if many people use the server, the form can be opened, closed, removed etc.
This is a Windows application (both Server and Client), so I'm not sure how a WebAPI comes in...
I'm looking into WCF, but I'm not sure how to code it...
-
Jul 11th, 2022, 12:14 PM
#5
Re: Need help with GUI for Service application
I use code like this - written many years ago...lots of stuff in the way, but the bottom line communication code is shown.
Code:
Private Function SendReader(cqMS As MemoryStream, ByRef returnMessage As String, acHold As Integer) As FSObject
Dim cl2 As New FSSerializer
Dim FSOb As New FSObject(-3)
Try
Dim prefixes() As String = {"http://localhost:8080/dcxReader/"}
If Not cl2.asyncPostFS(FSOb, prefixes, cqMS, returnMessage) Then
returnMessage = returnMessage & " Problem with asyncPostFS to " & prefixes(0)
End If
Catch ex As System.Exception
returnMessage = "SendReader: " & ex.Message
End Try
DisplayInfo(acHold.ToString & ".2", "", FSOb.DesiredAction, "?", FSOb.FileId.ToString, "", "", "", "", returnMessage, FSOb.SessionId.ToString)
Return FSOb
End Function
Code:
Public Function asyncPostFS(ByRef FSOb As FSObject, prefixes() As String, fsMS As MemoryStream, ByRef TraceMsg As String) As Boolean
Dim blnSuccess As Boolean = True
Try
Dim request As HttpWebRequest = DirectCast(WebRequest.Create(prefixes(0)), HttpWebRequest)
request.Method = "POST"
request.Headers.Add("x-package: fsob")
request.AllowWriteStreamBuffering = False
request.PreAuthenticate = True
'request.UserAgent = "fsob"
request.ContentType = "application/x-www-form-urlencoded"
request.ContentLength = fsMS.Length
Dim outputstream As Stream = request.GetRequestStream()
outputstream.Write(fsMS.ToArray, 0, CInt(fsMS.Length))
Dim response As WebResponse = request.GetResponse()
Dim datastream As Stream = response.GetResponseStream()
Deserialize(FSOb, datastream)
'FSOb.AffectCnt()
TraceMsg = FSOb.SessionId.ToString & ">F" & FSOb.FileId.ToString & " " & FSOb.DesiredAction & " " & FSOb.WhoFrom & " (Rcvd " & CInt((response.ContentLength + 1024) / 1024).ToString & " KB)" & tagList(FSOb)
outputstream.Close()
response.Close()
Catch ex As Exception
TraceMsg = ex.Message
blnSuccess = False
End Try
TraceMsg = System.Threading.Thread.CurrentThread.ManagedThreadId.ToString.PadLeft(2, "0"c) & " R) " & TraceMsg
Return blnSuccess
End Function
Code:
Private Sub RequestRcvd(ByVal result As IAsyncResult)
Dim acHold As Integer = System.Threading.Interlocked.Increment(m_asyncCount)
If Not m_listener.IsListening Then
DisplayInfo("", "", "", "", "", "", "", "RequestRcvd", System.Threading.Thread.CurrentThread.ManagedThreadId.ToString, "In Callback with " & acHold.ToString & " (not IsListening)...", "?")
Else
Dim context As HttpListenerContext = m_listener.EndGetContext(result)
m_listener.BeginGetContext(New AsyncCallback(AddressOf RequestRcvd), Nothing)
Dim request As HttpListenerRequest = context.Request
Dim cl2 As New FSSerializer
Dim FSOb As New FSObject(-3)
Dim returnMessage As String = ""
'Dim fileindex As Integer = 0
Dim response As HttpListenerResponse = Nothing
Try
If cl2.responseStart(request, FSOb, returnMessage) Then
DisplayInfo(acHold.ToString, ">> " & FSOb.WhoFrom, FSOb.DesiredAction, CInt((request.ContentLength64 + 1024) / 1024).ToString, FSOb.FileId.ToString, "", "", "RequestRcvd" _
, System.Threading.Thread.CurrentThread.ManagedThreadId.ToString, returnMessage, FSOb.SessionId.ToString)
'fileindex = FSOb.FileIndex
Dim GCId As Integer = GetFileId(FSOb.OriginalFileName)
FSOb.FileId = GCId ' acHold
FSOb.Posted = True
Dim FObHold As Byte() = FSOb.FileContent
FSOb.FileContent = (New MemoryStream).ToArray
FSOb.WhoFrom = "Librarian w/no filecontent"
FSOb.DesiredAction = "SetFileId"
Dim rtnSize As Long = cl2.responseEnd(response, context, FSOb, returnMessage)
FSOb.FileContent = FObHold
DisplayInfo(acHold.ToString, "", "", "", FSOb.FileId.ToString, FSOb.DesiredAction, CInt((rtnSize + 1024) / 1024).ToString, "", "", returnMessage, FSOb.SessionId.ToString)
End If
Catch ex As HttpListenerException
returnMessage = "RequestRcvd: " & ex.Message
Catch ex As System.Exception
returnMessage = "RequestRcvd: " & ex.Message
Finally
If response IsNot Nothing Then
response.Close()
End If
End Try
End If
End Sub
-
Jul 11th, 2022, 01:14 PM
#6
Thread Starter
Hyperactive Member
Re: Need help with GUI for Service application
I'm watching this tutorial about WCF https://www.youtube.com/watch?v=3Qt7...c2c1oCCU6GofYr, but I'm not sure how to implement it into my service...
If someone can help me with it, I'll be grateful!
Thanks
-
Jul 11th, 2022, 01:33 PM
#7
Re: Need help with GUI for Service application
Don't.
The guy is re-inventing the wheel and from a short view I gave this he is actually re-creating a WCF service. The worst kind of service available in all human kind.
You can either look at szlamany solution (the guys is practically giving away free stuff) or have a look here, but you need more stuff, preferable your own routes.
https://www.c-sharpcorner.com/articl...n-asp-net-mvc/
There is a WCF forum (includes Web Api) that you can ask if you have questions.
Again it's a sht sandwich at first.
Also may I ask why there is an issue to sprout the server part into a Web Api app? What exactly are you trying to do and why it's only limited to a windows application?
Doesn't the server have IIS standing by? The tutorial seems like it would be running on IIS anyhow (or not, I just watched the horror and closed it why a scream).
OK so ,also, if you don't want IIS, there is this: https://www.dotnetcurry.com/aspnet/8...pi-without-iis
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
Jul 11th, 2022, 02:06 PM
#8
Thread Starter
Hyperactive Member
Re: Need help with GUI for Service application
Originally Posted by sapator
Don't.
The guy is re-inventing the wheel and from a short view I gave this he is actually re-creating a WCF service. The worst kind of service available in all human kind.
Good to know, I'm a beginner with these networking stuff...
Originally Posted by sapator
You can either look at szlamany solution (the guys is practically giving away free stuff)
I tried to follow what he did there, I think it just gave me a headache...
Originally Posted by sapator
I don't know if I want it to be a web API
Originally Posted by sapator
There is a WCF forum (includes Web Api) that you can ask if you have questions.
Again it's a sht sandwich at first.
At first?
Originally Posted by sapator
Also may I ask why there is an issue to sprout the server part into a Web Api app? What exactly are you trying to do and why it's only limited to a windows application?
Doesn't the server have IIS standing by? The tutorial seems like it would be running on IIS anyhow (or not, I just watched the horror and closed it why a scream).
OK so ,also, if you don't want IIS, there is this: https://www.dotnetcurry.com/aspnet/8...pi-without-iis
All my computers are Windows (sadly)
So this is a continuation of my project here: https://www.vbforums.com/showthread....itoring-system, the next step is to make the Server and the Client a service (so as soon as the Windows boot up, the application would run - no need to log on).
I managed to get the Client side into a service, but I need the Server to issue commands to the Client (popup a timed message, logout a user, etc...).
And for that I need a GUI, and as we all know, Services can't have a GUI...
The Server side is just a VM Windows 10, I don't think I NEED it as a service, but it's cooler (don't you think?)...
The Server app has a GUI with a list of all the computers that are connected to it, I can right click a computer and send a "command" to the Client utilizing Asynchronous TcpListener & TcpClient.
To sum this up, I don't
-
Jul 11th, 2022, 07:30 PM
#9
Re: Need help with GUI for Service application
I've written a service application that is basically my own version of Team Viewer. I used a separate application for the GUI which uses Winsock to communicate with the service. The TCP/IP stack in Windows is one of the few things that can cross session boundaries.
-
Jul 12th, 2022, 09:06 AM
#10
Thread Starter
Hyperactive Member
Re: Need help with GUI for Service application
Originally Posted by Niya
I've written a service application that is basically my own version of Team Viewer. I used a separate application for the GUI which uses Winsock to communicate with the service. The TCP/IP stack in Windows is one of the few things that can cross session boundaries.
Can you please share your wisdom?
Or at least point me in the right direction...
Thanks
-
Jul 12th, 2022, 10:19 PM
#11
Re: Need help with GUI for Service application
Originally Posted by threeeye
Can you please share your wisdom?
Or at least point me in the right direction...
Thanks
I made a simple project years ago that shows how to use Winsock in .Net. Here.
-
Jul 13th, 2022, 01:24 PM
#12
Thread Starter
Hyperactive Member
Re: Need help with GUI for Service application
Originally Posted by Niya
I made a simple project years ago that shows how to use Winsock in .Net. Here.
My app is a Server Client via TcpListener, Can I have the Client application connect to a server with TcpListener, and be a server at the same time?
-
Jul 13th, 2022, 01:38 PM
#13
Re: Need help with GUI for Service application
Sure you can. There is no reason a client application cannot also be a server at the same time.
-
Jul 13th, 2022, 01:44 PM
#14
Re: Need help with GUI for Service application
Originally Posted by Niya
Sure you can. There is no reason a client application cannot also be a server at the same time.
There is very small limitation that is called firewall. Opening firewall ports in corporate environment is hard for non-technical reasons.
-
Jul 13th, 2022, 01:58 PM
#15
Thread Starter
Hyperactive Member
Re: Need help with GUI for Service application
Originally Posted by peterst
There is very small limitation that is called firewall. Opening firewall ports in corporate environment is hard for non-technical reasons.
LOL
I know that the firewall is a limitation.
I'm asking about the program limits...
And I don't think that you need to open ports in the firewall if you are connecting to localhost...
-
Jul 13th, 2022, 02:16 PM
#16
Re: Need help with GUI for Service application
Originally Posted by peterst
There is very small limitation that is called firewall. Opening firewall ports in corporate environment is hard for non-technical reasons.
True. But that may not apply in this case since we are talking about a GUI frontend using TCP/IP to communicate with a Windows Service backend on the same machine. It is even possible to confine the entire thing to just the loopback adapter.
-
Jul 13th, 2022, 02:29 PM
#17
Re: Need help with GUI for Service application
Originally Posted by threeeye
LOL
I know that the firewall is a limitation.
I'm asking about the program limits...
And I don't think that you need to open ports in the firewall if you are connecting to localhost...
I've read again the thread about monitoring app and that you are the IT manager, so no problem with firewalls :-)
I have different view on the design how monitoring system (servers, clients, whatever) should work, but I understand what you want with your system design.
I can give you example with FileZilla FTP server, where the FTP service is running as Windows Service, but the FileZilla Server Interface is separate application that connects to the service using different port. FTP part of FileZilla listens on port 21 (and others if you setup PASV and/or FTPS), while the management part listens on port 14147. Still same service, just more listening ports on the service side.
On the management client side (FileZilla Server Interface) you can add different servers you want to control in your network. It is just application that you can run and stay in tray when minimized.
You can do the same: expose two (or more) listeners in your app - one for remote clients and one for local management. No need to open the local management port if you will connect from localhost. But if you open it - you can connect from everywhere in your network and control what happens from different computers. But remote control needs securing the communication and do some authorization to disallow bad people in your network to try do something you don't want.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|