Results 1 to 17 of 17

Thread: Need help with GUI for Service application

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2011
    Posts
    256

    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.

  2. #2
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    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,

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  3. #3
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,597

    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.
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    May 2011
    Posts
    256

    Re: Need help with GUI for Service application

    Quote Originally Posted by szlamany View Post
    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)...

    Quote Originally Posted by sapator View Post
    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...

  5. #5
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    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

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    May 2011
    Posts
    256

    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

  7. #7
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,597

    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
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    May 2011
    Posts
    256

    Re: Need help with GUI for Service application

    Quote Originally Posted by sapator View Post
    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...

    Quote Originally Posted by sapator View Post
    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...

    Quote Originally Posted by sapator View Post
    or have a look here, but you need more stuff, preferable your own routes.
    https://www.c-sharpcorner.com/articl...n-asp-net-mvc/
    I don't know if I want it to be a web API

    Quote Originally Posted by sapator View Post
    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?

    Quote Originally Posted by sapator View Post
    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

  9. #9
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    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.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    May 2011
    Posts
    256

    Re: Need help with GUI for Service application

    Quote Originally Posted by Niya View Post
    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

  11. #11
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Re: Need help with GUI for Service application

    Quote Originally Posted by threeeye View Post
    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.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    May 2011
    Posts
    256

    Re: Need help with GUI for Service application

    Quote Originally Posted by Niya View Post
    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?

  13. #13
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    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.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  14. #14
    Fanatic Member
    Join Date
    Jun 2019
    Posts
    557

    Re: Need help with GUI for Service application

    Quote Originally Posted by Niya View Post
    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.

  15. #15

    Thread Starter
    Hyperactive Member
    Join Date
    May 2011
    Posts
    256

    Re: Need help with GUI for Service application

    Quote Originally Posted by peterst View Post
    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...

  16. #16
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Re: Need help with GUI for Service application

    Quote Originally Posted by peterst View Post
    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.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  17. #17
    Fanatic Member
    Join Date
    Jun 2019
    Posts
    557

    Re: Need help with GUI for Service application

    Quote Originally Posted by threeeye View Post
    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
  •  



Click Here to Expand Forum to Full Width