c# wcf duplex communication - wcf

I have to write an online chess program using WCF. I'm new to service programming, so could you please give me some advice.
I thought of using duplex communication, so that the service could poll the database and call the client, if the opponent has made a new step. but I don't think this would be a quite optimal solution. Could you please tell me what better alternatives can be here?
Thanks a lot.

Depends on the type of clients that will use the service. If for example the clients are .NET clients you could use wcf Net.Tcp communication and set up a callback contract that the clients need to implement and the service can call when someone makes a move. If you use other type of clients polling is probably the best way to go.

Related

WCF: Why WCF for a Windows Forms application?

I want to develop a simple Windows Forms application in C# using WPF and MVVM that will connect to an SQL server installed on a different machine. So I've read that, even for a simple structure like that, some developers would use WCF and make their application Service Oriented. I totally understand that SOA is the way to go with WebApps and SilverLight, but I don't see why, for a simple situation like a Winform and an SQL Server, would somebody use WCF. I would really appreciate if somebody could give me a couple of good reasons why to use WCF in my WinForm application (considering that the SQL Server will be in the same network with the clients)?
Thanks,
Aris
If you don't need it, don't use it :)
But you should consider whether there are plans to change the application - for example, to convert it to a web app or Silverlight. In that case, having a service which does the database access will make the conversion easier. Personally, I think this is usually over engineering, but it may make sense for your application if you foresee one such change in the near future.
Do you have to use WCF? Nope.
In my opinion, though, there aren't too many reasons NOT to create a WCF service for this sort of work.
Using WCF services for your different layers instead of class libraries is an excellent way to go. Using WCF, you can control how your components are hosted (IIS and http all the way down to in-process with named pipes) and where they're located.
WCF doesn't add much overhead and in return you get a bunch of benefits.
The point isn't necessarily to worry about SOA, but more to think ahead about flexibility and better reuse.
I can't think of a particularly compelling reason, other than habit. When you do something the same way for 99% of your projects, it's often just as easy to do it the same way for the other 1% if it doesn't go actively against your requirements.
The only other reason I can think of would be if you're writing something that could, potentially, be really useful externally or as a web-app. Using WCF in that instance would allow any client which could connect to the host (web browser, external application, or whatever) to connect to your library without you having to modify things after the fact.
If you know for (relatively) certain that this will only be a windows application run on the desktop of your own organizations' employees, I don't see a reason to use WCF in this instance.
Bottom line is that you're on a network so WCF or any web service makes sense.
Your network calls are all going to be async (or should be!). That's easy to do with WCF. Not so much with direct connections.
Even WinForm applications are connected these days.
I personally don't believe in creating services for everything, just to be creating services. Create a service when you know that you have a consumer for that service. Don't just say, "well, we might use it from another application some day", and call that an excuse for a service.
Services should be planned. The service contracts should be those which are required by their consumers. No consumers, no contracts, so no service.

webservice to WCF

we had developed a webservice in vb.net,framework 2.0. We would need to rewrite this
websevice in WCF with framework 3.5. Please provide some guidance regarding this and also
there are many othersystems consuming our webservice url. Will this conversion have impact on the source system or does it involve any build activity for the source system to consume the url that will be developed with WCF method?
Please provide sample example to have better understanding on this. Thanks!
A few thoughts.
Case 1: Your webservice is having consumers and you want to rewrite only the service and not disturb the consumers.
In this case using a basicHttpBinding end point with regular wcf service implementation would do. You can find many references to build WCF service with basicHttpBinding. Most probably this would fit your need.
Follwoing links may be helpful to you.
http://msdn.microsoft.com/en-us/library/aa480190.aspx
http://msdn.microsoft.com/en-us/library/ms731361(v=VS.90).aspx
Case 2: If You want to rewrite the service, and it is acceptable to have changes in the consumers, then it is worthy to consider the following points.
Endpoint Choice
a. If your preference is to keep your service interoperable (i.e. you would like the service to serve different platforms), Soap based endpoints would help. basicHTTPBinding, wsHTTPBinding, etc.
b. If your consumers are in the windows platform, and you prefer better performance than SOAP based bindings, netTCPBinding based endpoints would help.
c. If your consumers are in the same machine, netNamedPipe can would be a choice.
Service Design
The service design offers you to go with a lot of combination of the following.
a. Choice of deciding the service instance's life cycle.
b. Choice of Concurrency.
c. Choice of Sessions, and enforcing the order in which the service has to be called (prefered by specific designers)
d. Choice of having or not having the transactions.
You shouldn't need to change anything. It should work the same.
Have you tried migrating it yet? If so, what were the problems? If not, just switch it to 3.5 and see what happens.
The Only need is to change the service endpoints in WCF service making as
http://localhost/YourProjectName/Servicename.svc ,
Without changing the Server Side coding , You
need to expose the Remote Interfaces making them as [Service Contract] and the Methods as [Data Contract] on the client Side

Beginner Windows Service / WCF and front end GUI implementation Question

I am trying to figure out the best way to approach this design... Here is some background of what I'm trying to do:
I have a simple digital I/O controller that sends data to my computer via Ethernet. I have a program that can receive this data over Ethernet. I would like a separate front end application that presents this data in a GUI. I am trying to figure out the best way to interface the program that grabs the I/O data over Ethernet, and the program that displays this as the front end. This interface should run whenever the computer boots and constantly poll the I/O in the background.
I've read about Windows Communication Foundation (WCF) and this seems like a nice way to do this. As the windows service would quietly keep polling the I/O and any clients that attach to the WCF interface can present this data in a GUI.
Am I going about this all wrong? Does this seem like a good way to do things? How will my front end clients grab the data from the WCF service?
Thank you in advance.
That's precisely the way I have done it - hosting a WCF service in a Windows service. The Windows service is the process; the WCF service is where the work is done.
In my case, my WCF-based CollectionService is on standby most of the time. I use WCF to start and stop the collector because the WCF programming model makes this easy. However, to get the data from the collector to the UI, I use a TCP socket, not WCF. I know that WCF has a streaming mode, but (1) I've never used it and (2) I believe there is some amount of overhead using WCF this way. The socket is simply a comfortable fallback for me, but I think WCF could be made to work.
If you're just starting, you can refer to these two answers for getting your Windows service up and running using C#. From there, you'll just need to create the ServiceHost and close it in the OnStart() and OnStop() callbacks of your Windows service, respectively.
Easiest language for creating a
Windows service
How to make a
.NET Windows Service start right
after the installation?
If you are new to WCF, take a look at this SO question.
Good and easy books/tutorials to learn WCF latest stuff
One more thing. In the course of your work on this, you may find that you want the WCF service to provide events to your UI when certain things occur. For example, you might provide an event that periodically notifies the UI of the number of bytes that have been received. For this, I would strongly recommend this article by Juval Lowy, one of the WCF gods.
What You Need To Know About One-Way Calls, Callbacks, And Events
His Publish-Subscribe Framework is available for free at his website, IDesign.net, along with several other working WCF examples.
Hope this helps.

WCF competitive consumer pattern

Is it possible to create a WCF service (web service) that only accepts a single connection at any one time with all other calls either queued or rejected.
Need to implement the competitive consumer pattern where there are a number of clients which could deal with task at hand but when a client askes for more work a task must go to only one of them. Usual done as part of an enterprise service bus but can not find one that I'm happy to start using so looking to get this behaviour through a WCF service.
Any ideas people ?
Absolutely. You can set the ServiceThrottlingBehavior's maxConcurrentCalls to 1.
Have you looked at the distributor in NServiceBus? It does pretty much what you described.

Serial port communication using WCF?

Are there any bindings to communicate on Serial port using WCF?
OK I couldn't find any workable solution. Thus started to build a custom channel.
http://wcfserialchannels.codeplex.com
Interested developers please join.
i dont know how to do it ,but here is a Codeproject article on how to make your own transport for WCF. You could make one for to use a serial port. I am not familiar with WCF so i dont know if this article can help you, but it looks promising.
Hard to say without knowing more about what you're up to, but probably easiest to take it down a layer. If you're just talking about two machines where you control both sides, set up a Dialup Networking PPP connection between the machines over a null modem and use WCF with standard HTTP or NetTcp over the pipe.