WCF 이중 서비스에 문제가 있습니다.WCF 콜백에서받은 메시지가 잘못되었습니다.
[DeliveryRequirements(RequireOrderedDelivery = true)]
[(CallbackContract = typeof(IMyNotification), SessionMode = SessionMode.Required)]
public interface IMyService
{
[OperationContract]
void StartSomething();
...
}
서비스 구현 :
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Multiple)]
public class MyService : IMyService
{
...
}
콜백 인터페이스 :
[DeliveryRequirements(RequireOrderedDelivery = true)]
public interface IMyNotification
{
[OperationContract (IsOneWay=true)]
void NotificationAvailable(Notification notification);
}
클라이언트 콜백 구현 :
[CallbackBehavior (ConcurrencyMode = ConcurrencyMode.Multiple, UseSynchronizationContext = false)]
class MyServiceCallback : IMyNotification
{
public void NotificationAvailable(Notification notification)
{
lock (_NotificationLock)
{
// process notification...
}
}
}
이
내 서비스 인터페이스StartSomething() 메서드가 어떤 종류의 장치를 시작하고 그 메서드 내부에 장치가 "Starting"과 "Ready"두 가지 상태에서 시작한다고 가정 해 보겠습니다. 상태가 변경되면 클라이언트는 MyServiceCallback 클래스에서 NotificationAvailable을 통해 알림을받습니다.
주문 배달이 설정되어 있어도 NotificationAvailable 메서드 메시지 이 올바른 순서로 수신되지 않는 경우가 있습니다 (올바른 순서는 "시작"-> "준비 중"이지만 콜백은 "준비 중"> "시작 중").
일반적으로 StartSomething() 메서드의 첫 번째 호출에서 발생합니다. 어떤 종류의 스레드 경쟁 조건처럼 보입니다. MyServiceCallback에 ConcurrencyMode = ConcurrencyMode.Single을 설정하면 문제가 사라집니다.
이 문제를 해결하기위한 올바른 방법은 무엇입니까?