current OperationContext is null in WCF Windows Service

后端 未结 5 1612
感情败类
感情败类 2020-12-19 03:20

I am trying to set up a Publish/Subscribe system using WCF and where the WCF server is in a Windows service. The binding is net.TCP. The service is providing a \"Subscribe

5条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-19 04:11

    In the client code neither proxy created not channel factory. Service class instance is created as a class library.

    You should consume service as below code

     ServiceCallback serviceCallback = new ServiceCallback();
     InstanceContext instanceContext = new InstanceContext(serviceCallback);
    
     var pubsubProxy = new PubSubProxy.WcfPublisherContractClient(instanceContext);
     pubsubProxy.Subscribe();
    

    And when the service is running, OperationContext is created and you can access OperationContext.Current

提交回复
热议问题