简体   繁体   English

如果成员具有回调实现,io如何调用成员

[英]How io invoke member if member has callback implementation

I have a service object which has method having callback implementation mentioned below 我有一个服务对象,该对象具有下面提到的具有回调实现的方法

public string GetMacName()
{
string value = System.Environment.MachineName.ToString();
msgCallback = OperationContext.Current.GetCallbackChannel<IServiceCallBack>();
 msgCallback.Notify(value);
return value;
}

I have created a DuplexChannelfactory and got the service object in my client. 我创建了一个DuplexChannelfactory,并在客户端中获得了服务对象。 Now, with the service object I retrieve Type as Client Side: 现在,使用服务对象检索Type作为客户端:

DuplexChannelFactory<IServiceOne> factory = new DuplexChannelFactory<IServiceOne>(callbackInstance, new NetTcpBinding(), "uri");
proxyObject = factory.CreateChannel(); Type t=  proxyObject.GetType();

I have implemented IServiceOneCallback method in client 我已经在客户端中实现了IServiceOneCallback方法

public string Notify(string value)
{
Notification=value;
} 

I am invoking the method GetMacName() as mentioned below: 我正在调用方法GetMacName(),如下所述:

t.Invoke("GetMacName", BindingFlags.Default | BindingFlags.InvokeMethod, null, proxyObject, args); 

this is getting failed... where im wrong,is something for callback needs to done in Invoke 这越来越失败...我错了,是需要在Invoke中进行回调的事情

Got it working... [CallbackBehavior(ConcurrencyMode=ConcurrencyMode.Multiple,UseSynchronizationCon‌​text=false)] attribute needs to be added for wpf or winform application, something to do with synchronization context. 要正常工作... [CallbackBehavior(ConcurrencyMode = ConcurrencyMode.Multiple,UseSynchronizationCon‌text = false)]属性需要为wpf或winform应用程序添加,这与同步上下文有关。 Thank you for your inputs. 感谢您的投入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM