silverlight:使用SilverLight构建插件式应用程序( 9) —聊天插件客户端的实现

  这次是个在线聊天插件插件参考了MSDN中Duplex WCF服务实现和网上些聊天基本可以实现用户登录和聊天如果用户不存在就保存聊天数据到数据库等用户下次登陆时候读入

  这个是聊天时候图例:

使用SilverLight构建插件式应用<img src='/icons/68216chengxu.gif' />( 9) —聊天插件客户端<img src='/icons/68216de.gif' />实现为什么不使用在客户单添加WCF服务思路方法生成代理类然后进行编首先是生成代理类我没有发现可以实现WCF双向传输思路方法在网上也没有找到所以就参照msdn和些网上代码自己编写代理类进行操作:

  1: 定义聊天时候传输聊天数据实体参照服务器端聊天数据实体定义在客户端定义如下实体:

[DebuggerStepThroughAttribute]
  [GeneratedCodeAttribute(".Runtime.Serialization", "3.0.0.0")]
  [DataContractAttribute(Name = "ChatMessage", Namespace = "http://schemas.datacontract.org/2004/07/")]
  public partial ChatMessage : object
  {
    private DataField;
    private FromField;
    private ToField;
    private TypeField;
    private ContentField;
    [DataMemberAttribute]
    public Data
    {
      get
      {
         this.DataField;
      }
      
      {
         ((object.ReferenceEquals(this.DataField, value) != true))
        {
          this.DataField = value;
        }
      }
    }
    [DataMemberAttribute]
    public From
    {
      get
      {
         this.FromField;
      }
      
      {
         ((object.ReferenceEquals(this.FromField, value) != true))
        {
          this.FromField = value;
        }
      }
    }
    [DataMemberAttribute]
    public To
    {
      get
      {
         this.ToField;
      }
      
      {
         ((object.ReferenceEquals(this.ToField, value) != true))
        {
          this.ToField = value;
        }
      }
    }
    [DataMemberAttribute]
    public Type
    {
      get
      {
         this.TypeField;
      }
      
      {
         ((object.ReferenceEquals(this.TypeField, value) != true))
        {
          this.TypeField = value;
        }
      }
    }
    [DataMemberAttribute]
    public Content
    {
      get
      {
         this.ContentField;
      }
      
      {
         ((object.ReferenceEquals(this.ContentField, value) != true))
        {
          this.ContentField = value;
        }
      }
  
    }  


  这个实体类定义其实是可以自动生成

  2:把对WCF服务访问思路方法单独处理成个对象模式和结构基本和MSDN上那篇文章样:

 public void Start
    {
      // Instantiate the binding and the time-outs
      PollingDuplexHttpBinding binding = PollingDuplexHttpBinding
      {
        ReceiveTimeout = TimeSpan.FromSeconds(45),
        InactivityTimeout = TimeSpan.FromMinutes(1)
      };
      // Instantiate and open channel factory from binding
      IChannelFactory<IDuplexSessionChannel> factory =
        binding.BuildChannelFactory<IDuplexSessionChannel>( BindingParameterCollection);
      IAsyncResult factoryOpenResult =
        factory.BeginOpen( AsyncCallback(OnOpenCompleteFactory), factory);
       (factoryOpenResult.CompletedSynchronously)
      {
        CompleteOpenFactory(factoryOpenResult);
      }
    }
    void _disibledevent= txt;
          }
        }
      }
    }


  接受到区别信息的后把对应消息显示到区别窗口上免得混杂在起:

  至此聊天主要功能完成



Tags:  silverlight2 silverlight.2.0 silverlight是什么 silverlight

延伸阅读

最新评论

发表评论