Question

I write the WCF application. In service i have method and i want sync this method to all customers. So one client can use this method at the moment and rest client waiting when first client finish. I try [MethodImpl(MethodImplOptions.Synchronized)] but this not work. This is my service class

namespace WcfServiceLibrary1 {
    [ServiceBehavior(UseSynchronizationContext = false)]
    public class Service1 : IService1 {


        [MethodImpl(MethodImplOptions.Synchronized)]
        public List<String> getBrute() {
           //method body
        }
     }
}

How does synchronization methods in WCF?

Était-ce utile?

La solution

I think that setting only really makes sense in the context of a duplex binding (a callback) where the client has registered a callback from the server to the client. It is a slightly exotic situation. It basically says when you receive this callback from the server invoke it onto the main thread, rather than just running it on some arbitrary thread pool thread.

To do what you want, you need to create an explicit lock on the server:

public class Service1 : IService1 {
    private static readonly object @lock = new object();

    public List<String> getBrute() {
       lock (@lock)
       {
           //method body
       }
    }
 }
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top