简体   繁体   中英

Internal communication between a service and multiple user applications WCF C#

I'm currently working on a project in c# where I have a service running as LocalSystem, and a user application (tray app) running for each logged on user.

I need to have communications between the two. Initially I've set up an endpoint using NetTcpBinding on the service for the clients to connect to and supply their username. Thereafter the clients each set up an endpoint themselves as such; net.tcp://localhost:5001/UserApp/'username', with port sharing enabled. The service can then connect to that endpoint, knowing the username.

Though, when trying to get the program to work well with UAC I ran into some issues. Port sharing with UAC enabled requires the user to be registred in <'allowAccounts> of SMSvcHost.exe.config, and even though I've added the user, I still get the following errror when trying to register the endpoint;

The service endpoint failed to listen on the URI 'net.tcp://localhost:5001/UserApp/myuser' because access was denied. Verify that the current user is granted access in the appropriate allowAccounts section of SMSvcHost.exe.config.

I've also tried switching to NetNamedPipeBinding, which works well when hosting the user application. But when using this binding the service can not access the endpoints opened by the clients.

So, basically I need a way for a single service to provide an endpoint for multiple user applications on the same machine, and the service to be able to connect to and send event updates to multiple user applications.

Any suggestions?

in this case I would think about using callback channels instead of opening new services on the client (ok - it's almost the same but it fit nices into the WCF framework and setting). You can read about this here: What you need to know about One-Way Calls, Callbacks, And Events

You may want to also look Duplex services, in particular the 'wsDualHttpBinding'. It is designed to do just want you are asking... to allow both the service and client to send messages independently to each other.

http://msdn.microsoft.com/en-us/library/ms731064.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM