Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How do I add a timer and it's events in my WCF Application Service ?
My WCF receives files from a client and I save them in a SQL Server Database.
I would like to send the received files to an other service that I do not control. But I don't want to make the client wait for a return of the [OperationContract] while I do this. I want to send it afterwards.

Here's a code example of my original source
C#
public ServiceFeedback UploadFileToServer(byte[] file)
{
    FileModel dbFile = database.FileModel.Add(new FileModel(file)); // Adding to database...
    SendToOtherService(dbFile); // Sending to other service, I want to remove this from here and put it in an other function. It makes the client wait for the return

    if(NoErrors = true)
        return ServiceFeedback.OK;
    else
            return ServiceFeedback.ERROR;
}
Posted
Comments
johannesnestler 15-Jul-14 9:50am    
make the other service call async....
RaisKazi 15-Jul-14 10:32am    
Have you considered hosing your WCF in Windows Service Application? which will give you leverage of Timer feature.
Sergey Alexandrovich Kryukov 15-Jul-14 10:56am    
Why a timer? Please, explain your ultimate goals. How can you possibly send something to the service you don't control? At least such service can accept the files, but how a timer should help?
—SA
Yannick Brodard 16-Jul-14 3:13am    
Thank you for the comments, it helped me a lot. :)

1 solution

Thanks to the comments, I found out that I didn't need a timer but instead an async on the SendToOtherService(dbFile), so SendToOtherService became SendToOtherServiceAsync. Thank you very much for your comments.

C#
public async void SendToOtherServiceAsync(FileModel dbFile)
{
    // Preparing file for sending...
    string response = await Send(formatedDbFile);
}


The Send method contains the some XML that I send via https

C#
public Task<string> Send(FormatedFile file)
{
    return Task<string>.Factory.StartNew(() =>
    {
        // Sends XML via https...
        return response;
    });
}


If you have better solutions I would be happy to see them :)
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900