How do I check the connection status of my WCF service - winforms

I am currently developing a WCF publish subscribe service on a winform app. How do I code it in such a way that whenever a client subscribes to my service, I would be able to display a message in my textbox saying, "1 client has connected/disconnected to/from the service"

As marc said, clients don't maintain connections to WCF services, but you can monitor imaginary connections by having the clients regularly call an "I'm here" method on the service while they are "connected", and when they stop calling it, you consider them to be "disconnected". I've found this strategy to work well for a distributed processing application when I wanted to keep track of how many agents were available to do work.

Have a look at the Microsoft Duplex Services (WCF)
Duplex Services

Related

How to move BizTalk EAI services from on premises to Logic Apps which is using TCP/IP custom adaptors(designed by codeplex)

We have BizTalk EAI application which received request and send response to client using sokect switching (TCP/IP adaptors designed by codeplex) .
We need help to move EAI application from in premises to Logic Apps. Could anyone assist us to implement socket switching (TCP/IP adaptors/connectors or triggers) to receive request and sending response back to client
Thanks
Unfortunately, this is a notable gap in the available Connectors right now.
You best option is to stand up a Azure VM with a BizTalk Server instance to host this Adapter. You can connect it to the Logic Apps through Service Bus, Logic App Adapter or such.

Notify client application from wcf service

I have a wpf application which is running on diffrunt clients pc which get data from a wcf web service.
Now when update some data from web service I need to notify that to perticar client.
So I need to push data from web service to client
How can I do this?
Thanks in Advance.
You have to Use Duplex service in WCF
Sample Here
As mentioned by those above, a duplex service in WCF would work for you. There are alternatives though that achieve a similar function, but may not fulfill your needs.
SignalR
WebSockets
and server polling (you can google this for many various articles explaining it).
You can implement the Observer design pattern.
For my surprise, Wikipedia gives a very good definition on the first paragraph about this pattern.
http://en.wikipedia.org/wiki/Observer_pattern
Hope this works for you.

WCF client hosted in a windows service with a WPF UI

I have now a WCF service that is hosted inside a WPF application. It's running in a WCF server-client scenario where the client can call the server as well (duplex communications).
I would like to host the WCF client in a windows service, but I'd like to keep the WPF UI because of the functionality it provides when making calls back to the server (e.g. request information). I know that windows services don't have UI, but in this case I need it.
What best way is there to communicate between the WPF application and the windows service? (something better than sockets maybe?)
A scenario where this is useful would be something like:
from the WPF application I can choose what kind of information would be required from the WCF service acting as server,
this "command" would be sent to the windows service hosting the WCF client instance, and
using the the instance making the call to the server and
displaying the information in the WPF application via the WCF client service hosted by the windows service.
Thanks,
Adrian
Since the service is already running as WCF, how about exposing some extra "admin" methods on the WCF interface and have the WPF application interact with the service through those?
You'd have to put in a security layer to make sure only the legitimate user could call those new methods, but this solution might be the least work since the WCF infrastructure is already in place.

Should I use duplex WCF service or a regular WCF service?

I am currently developing a C# Windows Form Application that I intend to let it interact with a server. The server will receive posting from a mobile application that I have developed and whenever a posting is received, my Windows Form Application should be notified and give me a notification.
E.g. My mobile application sends an posting over to my server. Once my server receives the message, my windows form application should display a new notification showing the content of the message received and updates the UI accordingly.
In this type of scenario, it is better to use duplex WCF service or the just the regular WCF service?
If duplex, mind explaining why do I need to use duplex service? Thanks!
A duplex service is a service where two channels are created.
The first channel is the ordinary client -> server channel using your service contract. This is what you'll find in every WCF service, and is how your client can send a request to the service and it can respond.
The second channel is a server -> client channel using a different service contract that you define. This second channel is how the server can send messages to the client without the client requesting them.
In your scenario, you seem to indicate that an event taking place on the server should send a message to your client. If this is the case, then yes, you need a duplex service so that the second channel exists, which allows the server to notify your client without the client initiating a request.
Working on the assumption that your Windows app and your server are one the same domain I would suggest you use a publish/subscribe pattern for this type of interaction. You could use something along the lines of the IDesign sample which is available on their website. Essentially your Windows app is subscribing to events which are generated by your mobile application sending a posting to your server. Your publisher will then push the event to your Windows application.
To accomplish this your connection to the server/publisher needs to be always open. This is best achieved with tcpBinding as it is bi-directional and allows you to set high timeouts (effectively infinity).
If you cannot use TCP then your job has become a little harder. Using a duplex channel is a little problematic because you have to monitor the channel as well, because neither side will notifiy the other if the channel closes. You will only find out when you try to use it. This can still happen with the TCP connection of course but its a bit more stable that using http.
The other alternative is to use MSMQ binding. This will guarantee the delivery of your message because you are interacting via MSMQ rather than a communication channel such as http or tcp. In this instance you wouldn't even need the pub/sub framework, you could just have the service that receives your mobile posting send on a message to the queue, which your Windows application is monitoring. The upside to using the framework is that you can have multiple applications listening for the same event.
HTH.

Generate a WCF proxy for Silverlight without adding the ASync pattern to the WCF service without hosting the service

I got a coding scenario I can't seem to fix.
I got a synchronous WCF service and I want to simulate the Add Service Reference (slsvcutil.exe) but without hosting the WCF service. Is this possible?
I want use slsvcutil to generate the client from a wsdl file but it doesn't want to work because it needs an endpoint. Is it possible to generate a WCF proxy for Silverlight without hosting the service and without editting the WCF service by making all calls Asynchronous?
Is the reason you want to generate the proxies without hosting because you don't want to "add the asynch pattern"?
You don't have to edit the WCF service to make it callable asynchronusly, the asynch is all handled by the client not the server.
Take a look at this tutorial and you'll see that the service code doesn't mention asynch at all. http://www.dotnetcurry.com/ShowArticle.aspx?ID=228
Practically everything in Silverlight is asynchronus and for good reason. It's that way so that the end user doesn't experience blocked UI threads while the app goes off to fetch data.

Resources