セルフホストの WCF サービスが InstanceContextMode.PerCall を設定していても並列処理をしてくれない件
セルフホストで WCF のサービスを公開し、外部プログラム(Java)からアクセスしているんですが、 InstanceContextMode.PerCall を設定(呼び出しごとにインスタンスを生成)しても何故か直列で実行されてしまってるぽい。なんでだ?
で、みつけたのが、このスレッドです。
That explains. By default, if there is a synchronization context in the moment the service is started (which is the case for methods called by UI events on WPF/WinForms apps), then WCF will try to deliver all the calls in that same thread (so you can update some UI control within a service call, for example). You can turn this off by setting the [ServiceBehavior(UseSynchronizationContext = false)] in your service.
UIからサービスを起動してる場合、UIスレッドで実行しちゃう。こっちで直列になってしまうってことですね。なので UseSynchronizationContext = false を合わせて設定しなければならない、と。WCF なんて IIS に載っけちゃうことが多いと思うんですが、そうなると気づかないので多くの人はこんなところではハマらないわけで、あんまり情報がありませんでしたが、こんな罠があるとは……。