none
Creating a WCF Client in a service RRS feed

  • Question

  • Are there any examples of how to include a WCF Client in a windows service??

    Martin Autry

    Saturday, September 23, 2017 12:04 AM

Answers

  • I think there may be some confusion regarding service vs. server.  I guess the bottom line statement is if a WCF Client can be hosted by a windows service instead of an application.  It would connect to a server at startup.  If the connection is lost, it would periodically try to reconnect.  It would eventually pass state information from one server to another acting as client to both.

    Martin Autry


    A Windows service can be part of an application's infrastructure. And Windows service can host a WCF client that is in communication with a WCF service hosted by the local machine or a machine on the LAN or WAN.  
    • Marked as answer by dannyfarwin Monday, September 25, 2017 1:49 PM
    Sunday, September 24, 2017 2:52 AM

All replies

  • The WCF client works the same no matter what the .NET project type is about.

    https://docs.microsoft.com/en-us/dotnet/framework/wcf/accessing-services-using-a-wcf-client

    You take note that when Service Reference is created for client in the Windows service project, then an app.config is created in the project too, and a Windows service project is project that creates a programname.exe.

    <copied>

    An app.config is only used in debug runtime mode in Visual Studio.

    For IIS hosted solutions, the Web.config file is where .NET will look for any configuration information during application runtime. Any projects below the Web project, the root project, within the solution that have an app.config, the app.config information in the subordinate project must be copied to the web.config in the root project.

    If a project that creates a programname.exe file, a selfhosting exe, has an app.config, which is the root project, then another project within the solution that has an app.config, the app.config information in the subordinate project must be copied to the app.config in the root project.

    Why? It is because upon the successful build of solution, the root selfhosting exe project, VS will have its app.config copied over to a runtime config called programname.exe.config where .NET will look for config information at program runtime.

    The progamname.exe is deployed, and the progamname.exe.config must be deployed to the same location so .NET can find it.

    <end>

    CAPICHE?

    Saturday, September 23, 2017 12:37 AM
  • Yes, I think I see what you are referring to.  I need to configure what amounts to a client to client interface between two servers, which is somewhat unorthodox.  Instead of working directly with sockets, I wanted to see if I could do this with WCF Client interfacing hosted by a windows service.

    Martin Autry

    Saturday, September 23, 2017 1:46 AM
  • Yes, I think I see what you are referring to.  I need to configure what amounts to a client to client interface between two servers, which is somewhat unorthodox.  Instead of working directly with sockets, I wanted to see if I could do this with WCF Client interfacing hosted by a windows service.

    Martin Autry

    A WCF client can only be a client to a WCF service. A Windows service can host a WCF service. Therefore a Windows application can host the WCF client, the client can consume a WCF service and the WCF service can be hosted by a Windows service.

    https://www.codeproject.com/Articles/515253/Service-Oriented-Architecture-and-WCF

    Saturday, September 23, 2017 4:17 AM
  • I think there may be some confusion regarding service vs. server.  I guess the bottom line statement is if a WCF Client can be hosted by a windows service instead of an application.  It would connect to a server at startup.  If the connection is lost, it would periodically try to reconnect.  It would eventually pass state information from one server to another acting as client to both.

    Martin Autry

    Sunday, September 24, 2017 1:11 AM
  • I think there may be some confusion regarding service vs. server.  I guess the bottom line statement is if a WCF Client can be hosted by a windows service instead of an application.  It would connect to a server at startup.  If the connection is lost, it would periodically try to reconnect.  It would eventually pass state information from one server to another acting as client to both.

    Martin Autry


    A Windows service can be part of an application's infrastructure. And Windows service can host a WCF client that is in communication with a WCF service hosted by the local machine or a machine on the LAN or WAN.  
    • Marked as answer by dannyfarwin Monday, September 25, 2017 1:49 PM
    Sunday, September 24, 2017 2:52 AM
  • Hi Martin,

    >> Instead of working directly with sockets, I wanted to see if I could do this with WCF Client interfacing hosted by a windows service.

    What do you want to achieve by hosting WCF client in a windows service? You could host WCF Client in a windows service.

    >> It would connect to a server at startup.  If the connection is lost, it would periodically try to reconnect.  It would eventually pass state information from one server to another acting as client to both.

    What do you mean by passing state information? You could create WCF Client at atartup.

    I would suggest you try to follow the link from DA924x to check whether hosting WCF Client in a service meet your requirement. Without other requirements, I could say we could create WCF Client in a windows service.

    >> Accessing WCF Service via outgoing connection

    Is there any issue with this thread? If not, I would suggest you mark the helpful reply as answer which is the way to close a thread here. If there is, please feel free to keep following.

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, September 25, 2017 2:30 AM