When an operation has no return value, and the client does not care about the success or failure of the invocation. WCF offers one-way operations to support this sort of fire-and-forget invocation,: once the client issues the call, WCF generates a request message, but no correlated reply message will ever return to the client. The one-way message exchange pattern is useful when a client needs to send information to a service but doesn't receive a response. In reality, it's "fire and acknowledge" because the caller receives an acknowledgement that the message was successfully committed to the communication channel.
When a client sends a message to a service endpoint whose operation is marked as one-way, control is returned to the caller before the service operation completes. One-way operations are specified on the [OperationContract] attribute by using the IsOneWay=true modifier.

Configuring One-Way Operations

The OperationContract has a property IsOneWay which is Boolean type.
  1. [AttributeUsage(AttributeTargets.Method)]
  2. public sealed class OperationContractAttribute : Attribute
  3. {
  4. public bool IsOneWay
  5. { get; set; }
  6. }
Default value of IsOneWay property is false. You need to set IsOneWay to true to configures the method as a one-way operation:
  1. [ServiceContract]
  2. public interface IArticleService
  3. {
  4. [OperationContract(IsOneWay=true)]
  5. void OneWayMethod();
  6. }

One way Operation in WCF

  1. namespace WCFService
  2. {
  3. [ServiceContract]
  4. public interface IArticleService
  5. {
  6. [OperationContract(IsOneWay=true)]
  7. void OneWayMethod();
  8. [OperationContract]
  9. DataTable GetAllArticles();
  10. }
  11. }
  12. namespace WCFService
  13. {
  14. public class ArticleService : IArticleService
  15. {
  16. public void OneWayMethod()
  17. {
  18. // Some code here
  19. /////////////
  20. }
  21. public DataTable GetAllArticles()
  22. {
  23. using (var Context = new ArticleDBEntities())
  24. {
  25. DataTable objDt = new DataTable();
  26. objDt = Context.Articles.ToList().CopyToDataTable();
  27. return objDt;
  28. }
  29. }
  30. }
  31. }
Both service operations in service contract are implemented same but one is marked as one-way operation. When any client calls OneWayMethod the client-side proxy call returns immediately and doesn't wait for the response. When the client calls GetAllArticles the client-side proxy call blocks while the service executes the statement.
Client implemented code
  1. ArticleServiceClient proxy = new ArticleServiceClient();
  2. proxy.OneWayMethod();
  3. DataTable objDt = new DataTable();
  4. objDt = proxy.GetAllArticles();
  5. proxy.Close();
You should turn on reliability for your services, even for one-way calls. This will ensure delivery of the requests to the service
Sessionful Services with One-Way Operations
You can design a sessionful contract with one-way operations:
  1. [ServiceContract(SessionMode = SessionMode.Required)]
  2. interface IArticleService
  3. {
  4. [OperationContract(IsOneWay = true)]
  5. void OneWayMethod();
  6. }
If the client issues a one-way call and then closes the proxy while the method executes, the client will still be blocked until the operation completes.