• WCF 提高传输数据性能方法 补


    纪念Google.cn 正式离我们而去... 

    上一篇:WCF提高传输数据性能方法之二 (数据分割)

    前面两篇WCF提高传输性能的文章中提到的两个方法是可以合并在一起使用的。
    另外补一下传输DataSet的代码

    服务端
    private byte[] buffer = null;
    private int bufferSize = 10000;
    private long stream_length;

    private MemoryStream stream;


    private void InitDataSet(DataSet ds)
    {
    IFormatter formatter
    = new BinaryFormatter();
    stream
    = new MemoryStream();
    formatter.Serialize(stream, ds);
    stream.Position
    = 0;
    stream_length
    = stream.Length;
    }
    public byte[] GetBuffer()
    {
       
    if (buffer != null)
           
    return buffer;
       
    else
           
    return null;
    }

    public bool ReadBuffer()
    {
       
    bool exist;
       
    if (stream_length > 0)
        {
           
    if (stream_length > bufferSize)
            {
                buffer_currect
    = new byte[bufferSize];
                stream.Read(buffer,
    0, bufferSize);
                stream_length
    -= bufferSize;
            }
           
    else
            {
                buffer_currect
    = new byte[stream_length];
                stream.Read(buffer,
    0, (int)stream_length);
                stream_length
    = 0;
            }
            exist
    = true;
        }
       
    else
        {
            exist
    = false;
        }
       
    return exist;
    }
    客户端
    using (DataClient client = new DataClient())
    {
    MemoryStream stream
    = new MemoryStream();
    byte[] buffer;
    while (client.ReadBuffer())
    {
    buffer
    = client.GetBuffer();
    stream.Write(buffer,
    0, buffer.Length);
    }
    stream.Position
    = 0;
    IFormatter formatter
    = new BinaryFormatter();
    DataSet ds
    = (DataSet)formatter.Deserialize(stream);
    stream.Close();
    client.Close();
    return ds;
    }
  • 相关阅读:
    QTreeWidget创建
    Qt QTreeWidget节点的添加+双击响应+删除详解(转)
    Qt QTreeWidget 树形结构实现(转)
    QMessageBox类学习:
    QAction类详解:
    Qt事件和信号的区别 .
    Qt消息机制和事件(二)
    Qt消息机制和事件(一)
    初步开始学习图
    图中最短路径算法(Dijkstra算法)(转)
  • 原文地址:https://www.cnblogs.com/stangray/p/1692535.html
Copyright © 2020-2023  润新知