wcf DuplexHttpBinding双向通信
来源:互联网 发布:大学生网络暴力感悟 编辑:程序博客网 时间:2024/06/06 02:47
一:建立接口 CallbackContract = typeof(ICallback)指定需要回调通信的接口,该接口方法由前端实现
[ServiceContract(CallbackContract = typeof(ICallback))]
public interface IUserCallBack
{
[OperationContract]
ReturnData<string> Login(string username, string password);
}
public interface ICallback
{
[OperationContract(IsOneWay = true)]//单向调用,不需要返回值
void LoginCallBack(string hello);
}
二:实现接口
public class UserCallBack : IUserCallBack
{
UserDao ud = new UserDao();
public ReturnData<string> Login(string username, string password)
{
ICallback callbackt = OperationContext.Current.GetCallbackChannel<ICallback>();
callback.LoginCallBack("successful");//可以进行直接回调当前客服端的实现的LoginCallBack方法
如何需要回调特定的客服端就把callbackt 与用户标识放到键值对里,在更具特定的情况回调客服端方法
}
}
三:进行wcf配置
<!--这里是添加的开始-->
<services>
<service name="JSDService.Users.UserCallBack" >
<endpoint address="" binding="pollingDuplexHttpBinding" contract="JSDService.Users.IUserCallBack" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<extensions>
<bindingExtensions>
<add name="pollingDuplexHttpBinding" type="System.ServiceModel.Configuration.PollingDuplexHttpBindingCollectionElement,System.ServiceModel.PollingDuplex"/>
</bindingExtensions>
</extensions>
<!--这里是添加的结束-->
四:siverlight前端 直接放一个按钮进行测试
<Grid x:Name="LayoutRoot" Background="White">
<TextBox Height="23" HorizontalAlignment="Left" Margin="12,12,0,0" Name="textBox1" VerticalAlignment="Top" Width="120" />
<Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="12,41,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
<TextBlock Height="23" HorizontalAlignment="Left" Margin="12,70,0,0" Name="textBlock1" Text="TextBlock" VerticalAlignment="Top" Width="120" />
</Grid>
ServiceReferenceTest.UserCallBackClient client;
public MainPage()
{
InitializeComponent();
//扩展的轮询机制的双向通讯
PollingDuplexHttpBinding binding = new PollingDuplexHttpBinding()
{
//每次轮询建立的有效时间为20分钟
InactivityTimeout = TimeSpan.FromMinutes(20)
};
//基础的http请求方式
//Binding binding =new BasicHttpBinding();
//svc服务地址
EndpointAddress endPoint = new EndpointAddress("http://localhost:8087/Users/UserCallBack.svc");
client = new ServiceReferenceTest.UserCallBackClient(binding, endPoint);
//异步调用SayHellow方法
//client.SayHellowAsync(this.textBox1.Text);
//调用完成后ShowHello回调事件
client.LoginCallBackReceived += client_LoginCallBackReceived;
client.LoginCompleted += client_LoginCompleted;
}
void client_LoginCallBackReceived(object sender, ServiceReferenceTest.LoginCallBackReceivedEventArgs e)
{
MessageBox.Show(e.hello);
}
void client_LoginCompleted(object sender, ServiceReferenceTest.LoginCompletedEventArgs e)
{
MessageBox.Show(e.Result.Value);
}
private void button1_Click(object sender, RoutedEventArgs e)
{
client.LoginAsync("aj","aj");
}
- wcf DuplexHttpBinding双向通信
- WCF的双向通信
- 关于WCF双向通信的想法
- WCF后续之旅(9):通过WCF的双向通信实现Session管理
- [原创]WCF后续之旅(9): 通过WCF双向通信实现Session管理[Part II]
- [原创]WCF后续之旅(9):通过WCF的双向通信实现Session管理[Part I]
- WCF Learning(3):在WCF中实现双向通信(Bi-directional Communication)
- WCF Learning(3):在WCF中实现双向通信(Bi-directional Communication)
- 稳扎稳打Silverlight(23) - 2.0通信之调用WCF的双向通信(Duplex Service)
- 稳扎稳打Silverlight(23) - 2.0通信之调用WCF的双向通信(Duplex Service)
- WCF 项目应用连载[3] - 双向通信 实例管理与服务端监控
- [原创]我的WCF之旅(3):在WCF中实现双向通信(Bi-directional Communication)
- WCF服务通过TCP实时监控客户端状态,并可以向客户端广播推送消息,实现双向通信
- socket 双向通信
- socketpair双向通信
- 双向通信管道
- Wcf
- WCF
- How to Install Android on Your PC
- Android调用Google Map
- C语言 二维数组(指针)动态分配和释放
- C#编写windows 服务 安装及卸载
- 【程序员的自我修养】第12章 系统调用与API
- wcf DuplexHttpBinding双向通信
- java简单标签的使用
- struts 拦截器(Interceptors)
- ORA-12560: TNS: 协议适配器错误的问题
- 【设计模式】创建型模式-抽象工厂
- IntentFilter---意图过滤器
- 一个最简单的Makefile例子
- Hive与Hbase使用域
- HDU1677:Nested Dolls