Results 1 to 11 of 11

Thread: WCF: Can an application that runs a WCF service also be a client?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2008
    Location
    Zeist, The Netherlands
    Posts
    266

    WCF: Can an application that runs a WCF service also be a client?

    While experimenting with WCF I have built a chat service. I have succesfully tested this service in the following scenarios:
    • Hosting the service in a console app, connecting with a windows forms app.
    • Hosting the service in a WPF app, connecting with the windows forms app.
    • Hosting the service in the console app, connecting with the WPF app.

    So the WPF app can succesfully host the service, as well as connect to it. But when I try to this at the same time, my attempt to connect to the service times out after 60 secs.
    I can't figure out why? Anyone else have an idea? Do you need to do something special for that?

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2008
    Location
    Zeist, The Netherlands
    Posts
    266

    Re: WCF: Can an application that runs a WCF service also be a client?

    Found it.... it's a threading issue. If you run the service in the UI thread, you can't start the client from the UI thread as well, because that creates a deadlock. So the solution is to start the service in a seperate thread.
    Sounds like the smart thing to do anyway, when you're self-hosting a service, to keep it seperate from the UI.

  3. #3
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: WCF: Can an application that runs a WCF service also be a client?

    Cool, thanks for sharing the solution
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: WCF: Can an application that runs a WCF service also be a client?

    And to also not have the UI as well as the service in the same app, that sort of defeats the purpose. The 60 seconds timeout was probably lucky enough, it's a default setting you should find in your web.config.

    Take that with a pinch of salt though, I do mean a UI that references its own service rather than a class library.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2008
    Location
    Zeist, The Netherlands
    Posts
    266

    Re: WCF: Can an application that runs a WCF service also be a client?

    I don't understand what you mean... sorry.

  6. #6
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: WCF: Can an application that runs a WCF service also be a client?

    I am equally confused by that post, perhaps you could elaborate mendhak
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  7. #7
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: WCF: Can an application that runs a WCF service also be a client?

    Right, so if you have an app that manages contact details and that also hosts a service, then the best practice is to keep the business logic in... you guessed it - the business logic layer. Then, your UI portion should talk to the business logic and not to the service itself. The service should remain 'reserved' for other apps to connect to it.

    Am I making sense now?

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2008
    Location
    Zeist, The Netherlands
    Posts
    266

    Re: WCF: Can an application that runs a WCF service also be a client?

    Yes, that makes sense, but how do you suggest to make the distinction between the service itself and the business logic layer?

  9. #9
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: WCF: Can an application that runs a WCF service also be a client?

    I dont understand the whole 'layer' thing When people say the business logic layer, is it just a conceptual thing or is there actually something that separates each of these 'layers' ? I guess that kind of discussion is for another thread though..
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  10. #10
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: WCF: Can an application that runs a WCF service also be a client?

    I think it's the same discussion. Let's say there's a piece of functionality that should take a Contact class and add it to the database. Your BL may then contain a method called

    AddContact(Contact newContact, string userId)

    Your WCF service can have a method called

    AddContact(Contact newContact, string userId)

    Note that they look exactly the same, but the WCF method should call the BL method. The BL method should validate the Contact, userid, anything else required, any validation required, then call the data layer to insert into the database. The UI should also call this BL method. The UI should not open a connection to the WCF service it is hosting.

    See, it all makes sense!!!11shiftone

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2008
    Location
    Zeist, The Netherlands
    Posts
    266

    Re: WCF: Can an application that runs a WCF service also be a client?

    Ah, I see your point. But in my case, the program is a P2P chat application. One of the peers will start both the server and the client, and the other side only the client. They both need to use the service because that delivers the messages to all clients, including the client running on the server side.

    Hope that made sense.... WCF discussions seem destined to be confusing.

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