|
-
Feb 27th, 2009, 04:08 AM
#1
Thread Starter
Hyperactive Member
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?
-
Feb 27th, 2009, 05:16 AM
#2
Thread Starter
Hyperactive Member
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.
-
Feb 27th, 2009, 05:26 AM
#3
Re: WCF: Can an application that runs a WCF service also be a client?
Cool, thanks for sharing the solution
-
Mar 4th, 2009, 02:15 PM
#4
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.
-
Mar 4th, 2009, 02:17 PM
#5
Thread Starter
Hyperactive Member
Re: WCF: Can an application that runs a WCF service also be a client?
I don't understand what you mean... sorry.
-
Mar 4th, 2009, 05:35 PM
#6
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
-
Mar 5th, 2009, 03:15 AM
#7
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?
-
Mar 5th, 2009, 05:19 AM
#8
Thread Starter
Hyperactive Member
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?
-
Mar 5th, 2009, 06:16 AM
#9
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..
-
Mar 6th, 2009, 05:27 AM
#10
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
-
Mar 6th, 2009, 05:35 AM
#11
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|