• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 295
  • Last Modified:

Writing a C# service general question

I haven't done this before so I'm hoping for a little guidance from those that have.

I need to write a service that runs on top of W2k8.  This service needs to take direction from an application running on another server and report back on the status / completion of the task.

The "master" application is a C# data app running against an MSSL DB.

I'm looking for sample code and suggestions on the best way to accomplish this task.

Thanks for your insight.
0
sej69
Asked:
sej69
  • 5
  • 3
  • 2
  • +1
1 Solution
 
angus_young_acdcCommented:
It all depends on what exactly you want to report on?  Is your application logging what its doing?  
0
 
sej69Author Commented:
I'm providing a task to the service to complete then reporting back to my main application on how it did with the task, it won't be a bool response but instead there will be lists of data to be sent back to the master application.
0
 
SimplistCommented:
I suggest you read the pages under http://msdn.microsoft.com/en-us/library/gg132851.aspx and follow the tutorials. Please find introductory tutorials on the field of WCF Data Services at http://msdn.microsoft.com/en-us/data/bb931106
Be sure to select the appropriate version of the .NET frramework ( at the top of the pages of the particular tutorial)
Code examples will be included with the tutorials. Good Luck.
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
MlandaTCommented:
How long does the "task" take to run? If these are long running tasks, then you may need to consider a solution using message queueing for communication between the two applications as opposed to just WCF Data Services, where the general expectation is that the processing of the "task" is short (perhaps a couple of seconds or so).
0
 
sej69Author Commented:
MlandaT, I was just logged on to write something similar to that...

The tasks could take a long time to complete.  I also would like to get away from requiring the user from installing IIS.  (I am going to look at the OData connections for another feature I plan on writing in the future though).

For this functionality I would like to talk directly to the service running on another server and be able to accept a response back when complete.  What libraries do I need to look at for ""message queing?

Thanks!
0
 
SimplistCommented:
If the tasks take quite some time there will be no other option than to implement asynchronised services that will report results back when they are finished, instead of synchronised services that will be awaited for the results. With asynchronous services the protocol will need to provide the option to communicate the endipoint to report results to the requesting services.
0
 
MlandaTCommented:
MSMQ: Maybe these references might help.
http://msdn.microsoft.com/en-us/library/ms978425.aspx
http://www.dotnetfunda.com/articles/article1119-sending-and-receiving-message-in-msmq-using-csharp.aspx

MSMQ Installation: http://msdn.microsoft.com/en-us/library/aa967729.aspx

With WCF, there is an option to use an MSMQ binding, which is nice because it makes the fact that you are using MSMQ transparent to the client application.

"For this functionality I would like to talk directly to the service running on another server and be able to accept a response back when complete."
You need to think about the way you process your responses. This is really determined by the life-cycle of the client application.

The WCF option makes it "easier" to process the response since the calling application basically "waits" for the WCF call to finish. There is of course the option to call the WCF service asynchronously and use an AsyncCallback (http://msdn.microsoft.com/en-us/library/ms734701.aspx, http://msdn.microsoft.com/en-us/library/ms731177.aspx) to be notified when the call completes. However, this approach is best suited to times when the "long" processing will complete during the calling applications lifetime. e.g. If the client initiates the call, and then it shuts down BEFORE the server has finished processing... that response will be lost. The client application might shut down for any of several reasons e.g. usr going home and shuts down their machine, OR they reboot OR there is a power failure OR network failure.... anything really. Bottom line... the client must be alive in order to process the response, since it's sent back as soon as processing is complete.

If however, you really cannot predict whether the "long" processing will be done during the calling clients application's lifetime OR it is likely that the processing, will outlast the client application, then MSMQ might be a good mechanism to communicate back and forth between the client app and the service. You can implement the server as a WCF service which will receive incoming requests for work (using MSMQ might be a good idea in case the server cannot process that incoming message immediately, so it may place it on a queue). The server will then do it's processing and when it's done, it will write a response onto some persistent storage which the clients can access to see whether there is a result etc etc. This will not necessarily require the client app to be running, but it should then be smart enough to pick up "responses" left for it by the server.
0
 
MlandaTCommented:
The "best" solution is really dependent on specific aspects of your application. The reality is that offloading processing to a remote server and figuring out how to consume the results of such processing can really be anything from a very simple 10 minute job, to a complex undertaking. In most cases, I find that the determining factor is the amount of time it will take to do the remote processing and perhaps how critical it is for the client to be aware of the status of the processing. If it's quick, like 2 seconds, then it could be a 10 minute job, otherwise if the remote server needs 2 hours to do the processing, then things might change very quickly. A lot can happen in 2 hours - the client can shutdown, etc.
0
 
sej69Author Commented:
I need to report back that the request has been completed for the "master" server to complete the task once the slave is done.  The job length should be somewhere around a few seconds to 10-20 minutes depending on the request size.  
0
 
sej69Author Commented:
Decided against running application as a server.  Instead I'm going to start the application on boot.
0
 
sej69Author Commented:
Not doing a service for this app.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 5
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now