当前位置: 首页 > news >正文

武汉便宜做网站公司专业网站优化

武汉便宜做网站公司,专业网站优化,软件开发大概需要多少钱,北京网站建设联系电话在WCF应用callback模式时,一些指导性的document给出的建议是将callback contract内的operation的Message Exchange Pattern设置为IsOneWay. 当然,当service调用callback而不需要从client instance获得callback的return value的时候,MEP设置为…

在WCF应用callback模式时,一些指导性的document给出的建议是将callback contract内的operation的Message Exchange Pattern设置为IsOneWay.

当然,当service调用callback而不需要从client instance获得callback的return value的时候,MEP设置为IsOneWay不失为最好的选择了。但是如果在某些应用场景下,我们需要获得客户端callback结果时候,就不能将MEP设置为IsOneWay=true了。

当然,当MEP设置为IsOneWay=false的时候,其他同步设置必须相应match,即ConcurrentMode只能为ReEntrant或者Multiple。

下面给出一个简单的应用模式:在线实时投票。

其简单系统模型如下:

WCF service提供一个简单的投票服务,收集投票结果通过callback机制得到各个client的结果后然后返回给service,然后WCF service给出statistics.

 针对这样的投票模型,在设置service的时候需要注意的是:

1.callback contract中的operation一定要设置为IsOneWay=false。否则callback无法return至服务端

2.ConcurrentMode不能设置为Single,而只能为ReEntrant或者Multiple.

3. 当service callbacks client的时候,callback result的处理权在service,比如对结果进行统计处理等等。

下面给出主要的source code:

callback contract和service contract的定义

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;

namespace WCFCallBack
{
    [ServiceContract]
    
public interface ICaculatorCallBack
    {
        [OperationContract]
        
int Equals(int result);
    }

    [ServiceContract(CallbackContract
=typeof(ICaculatorCallBack))]   
    
public interface ICaculatorService
    {
        [OperationContract]
        
void AddTo(int n);

        [OperationContract]
        
void Register();
    }
}

servicecontract implementation以及消息发布

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;

namespace WCFCallBack
{
    
public class AddEventAgrs : EventArgs
    {
       
public int result;
    }

    [ServiceBehavior(ConcurrencyMode
=ConcurrencyMode.Reentrant)]
    
class CaculatorService:ICaculatorService
    {
        
public delegate void AddEventHandler(object sender, AddEventAgrs e);
        
public static event AddEventHandler OnAddCompleted;
        
public ICaculatorCallBack callback;
        
public int result;

        
public CaculatorService()
        {
            result 
= 0;
            Console.WriteLine(
"A Calculator Instance is constructed");
        }

        
public void Register()
        {
            callback 
= System.ServiceModel.OperationContext.Current.GetCallbackChannel<ICaculatorCallBack>();
            OnAddCompleted 
+= new AddEventHandler(CaculatorService_OnAddCompleted);
        }


        
void CaculatorService_OnAddCompleted(object sender, AddEventAgrs e)
        {
            Console.WriteLine(
"the OnAdd event has been triggered");
            Console.WriteLine(
"the callback result from client is "+callback.Equals(e.result));

        }

        
public void BroadAddEvent(AddEventAgrs e, AddEventHandler temp)
        {
            
if (OnAddCompleted != null)
            {
                
foreach (AddEventHandler handler in temp.GetInvocationList())
                {
                    handler.BeginInvoke(
this, e, nullnull);
                }
            }
        }
       
        
public void AddTo(int n)
        {
            AddEventAgrs e 
= new AddEventAgrs();
            
this.result += n;
            e.result 
= result;
            BroadAddEvent(e, OnAddCompleted);
        }
    }
}

client1 callback实现:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WCFClient
{
    
class CallBack:ICaculatorServiceCallback
    {
        
public int Equals(int n)
        {
            
//Console.WriteLine("haha");
            Console.WriteLine("this callback is implemented on client,the callback result is {0}", n.ToString());
            
return 2*n ;
        }
    }
}

client2 callback implementation

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WCFClient
{
    
class CallBack:ICaculatorServiceCallback
    {
        
public int Equals(int n)
        {
            Console.WriteLine(
"I have received a broadcasting news,the callback result is {0}", n.ToString());
            System.Threading.Thread.Sleep(
2000);
            
return n * n;
        }
    }
}

运行结果:

service screenshot

client1 screenshot

client 2 screenshot

转载于:https://www.cnblogs.com/Winston/archive/2008/12/02/1345647.html

http://www.lbrq.cn/news/2781109.html

相关文章:

  • 常州门户网站建设软文发布推广平台
  • 在哪个网站做一件代发靠谱吗怎么做一个网站平台
  • 毕业设计资源网站陕西seo
  • 做网站多少钱西宁君博专注怎样和政府交换友链
  • 厦门知名网站建设百度快照手机版
  • 西宁 专业网站建设重庆网站设计
  • 做图文链接网站武汉大学人民医院院长
  • Wordpress怎么配合HTML江西seo推广方案
  • A00网站建设windows优化大师和鲁大师
  • 网站代码规范网络公司有哪些
  • 做php网站用什么软件好免费引流在线推广
  • 安徽做网站哪家好搜索引擎营销的原理是什么
  • wordpress 百度cdnseod的中文意思
  • 阿里云做网站的代码每天新闻早知道
  • 江门网站建设公司开发网站用什么软件
  • 浦口区网站建设质量推荐今日新闻内容
  • 凡客建站免费的可以用多久郴州网络推广外包公司
  • 一个服务器下怎么做两个网站搜狗推广登陆
  • 武汉最大的广告公司网站seo推广
  • 深圳网站优化企业软文小故事200字
  • 首码项目推广网站电商平台怎么做
  • 北京模板网站开发全包seo入门培训学多久
  • 怎么做网站打赏农产品推广方案
  • 服务器分配网络提高网站访问速度b站怎么推广
  • 夸网站做的好怎么夸护肤品推广软文
  • 太原公司网站建设百度网盘云资源搜索引擎
  • 企业网站建设方案包含百度如何注册公司网站
  • 企业网站的建立与维护论文常德网站建设制作
  • www.qd2008 网站建设百度站长平台app
  • 昆明网站做的好的公司哪家好汕头seo推广外包
  • 双模式 RTMP H.265 播放器解析:从国内扩展到 Enhanced RTMP 标准的演进
  • 19.web api 10
  • 链表-2.两数相加-力扣(LeetCode)
  • 理解AQS的原理并学习源码
  • 【深度长文】Anthropic发布Prompt Engineering全新指南
  • 华清远见25072班C语言学习day11