在Thread中调用WCF方法时出现异常

时间:2017-09-06 08:25:03

标签: c# multithreading wcf binding duplex

我有一个不正常的问题,到目前为止谷歌还没有任何帮助。

我使用WSDualHttpBinding设置了与WCF服务器的DUPLEX客户端连接,这很好用。然后我将客户端连接放在一个线程中,现在我收到了这个异常(Message,Stack,InnerException):

  

线程正在中止。北   System.ServiceModel.Channels.SecurityBindingElement..ctor()[14948]
  北   System.ServiceModel.MessageSecurityOverHttp.CreateSecurityBindingElement(布尔   isSecureTransportMode,Boolean isReliableSession,   MessageSecurityVersion版本)[14948] bei   System.ServiceModel.WSDualHttpBinding.CreateBindingElements()[14948]   bei System.ServiceModel.Channels.Binding.EnsureInvariants(String   contractName)[14948] bei   System.ServiceModel.Channels.ServiceChannelFactory.BuildChannelFactory(ServiceEndpoint   serviceEndpoint,Boolean useActiveAutoClose)[14948] bei   System.ServiceModel.ChannelFactory.OnOpening()[14948] bei   System.ServiceModel.Channels.CommunicationObject.Open(时间跨度   超时)[14948] bei   System.ServiceModel.ChannelFactory.EnsureOpened()[14948] bei   System.ServiceModel.DuplexChannelFactory 1.CreateChannel(InstanceContext callbackInstance, EndpointAddress address, Uri via) [14948] bei System.ServiceModel.ClientBase 1.CreateChannel()[14948] bei   System.ServiceModel.ClientBase 1.CreateChannelInternal() [14948]
bei System.ServiceModel.ClientBase
1.get_Channel()

设置连接并调用方法的类方法调用如下:

await Task.Run(() => new ClientConnector().LoadIT());

设置如下(在LoadIT方法中):

 try
            {
                var FXDuplexCallback = new FXDuplexCallback();
                FXDuplexCallback.ServiceCallbackEvent += HandleServiceCallbackEvent;

                var instanceContext = new InstanceContext(FXDuplexCallback);
                var dualHttpBinding = new WSDualHttpBinding();

                dualHttpBinding.ReceiveTimeout = TimeSpan.MaxValue;
                dualHttpBinding.ReliableSession.InactivityTimeout = TimeSpan.MaxValue;
                dualHttpBinding.SendTimeout = new TimeSpan(00, 00, 03);
                dualHttpBinding.CloseTimeout = TimeSpan.MaxValue;

                var endpointAddress = new EndpointAddress(sServiceEndpointUri);
                oProxy = new FXDuplexProxy(instanceContext, dualHttpBinding, endpointAddress);

                //Start client connection with OpenTF and receive current user data.
                oRoomData = oProxy.FXClientConnect();
            }
            catch (Exception e)
            {
                Debug.WriteLine("e.Message + e.StackTrace + e.InnerException);
                oProxy.Abort();
            }

FXDuplexProxy是继承自DuplexClientBase< 服务器合约接口>

的类

我不知道为什么只有当我在线程中运行连接时才会发生此异常,是否有人有任何想法?

0 个答案:

没有答案
相关问题