zoukankan      html  css  js  c++  java
  • 2010年07月 小记(telnet,xml命名空间,MaxItemsInObjectGraph, IIS传输限制, memcached Telnet Interface)

    1、在Windows 2008 R2下安装telnet客户端

    PS C:\Users\Administrator> servermanagercmd -install telnet-client

    2、使用XmlSerializer时移除xml声名和默认命名空间。

    代码
    protected string ToXml(object objectToConvert)
    {
    string str = null;

    using (MemoryStream stream = new MemoryStream())
    {
    //XmlWriterSettings.OmitXmlDeclaration移除xml声明
    using (XmlWriter xmlWriter = XmlTextWriter.Create(stream, 
                 new XmlWriterSettings() 
                { OmitXmlDeclaration = true, Encoding = Encoding.UTF8 }))
    {
    //移除命名空间
    XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
    ns.Add(
    "", "");

    XmlSerializer serializer
    = new XmlSerializer(objectToConvert.GetType());
    serializer.Serialize(xmlWriter, objectToConvert, ns);

    byte[] buffer = new byte[stream.Length];
    stream.Position
    = 0;
    stream.Read(buffer,
    0, (int)stream.Length);

    str
    = Encoding.UTF8.GetString(buffer);
    xmlWriter.Close();
    }
    stream.Close();
    }

    if (str != null)
    {
    str
    = str.Trim();
    }

    return str;
    }

    3、WCF通信中如果出现序列化错误,如:

    "对象图中可以序列化或反序列化的项目数目上限为“65536”"

    请注意配置MaxItemsInObjectGraph。

    #通过代码配置:

               foreach (var op in client.Endpoint.Contract.Operations)
                {
                    var dataContractBehavior = op.Behaviors[typeof(DataContractSerializerOperationBehavior)]
                    as DataContractSerializerOperationBehavior;
     
                    if (dataContractBehavior != null)
                    {
                        dataContractBehavior.MaxItemsInObjectGraph = int.MaxValue;
                    }
                }
    

    #通过配置修改:

    <dataContractSerializer maxItemsInObjectGraph="2147483647" />

    4、IIS传输限制

    <httpRuntime maxRequestLength="20000" executionTimeout="600" />


    5、memcached Telnet Interface



  • 相关阅读:
    php设计模式之观察者模式
    git tag 相关命令
    git 命令
    phpstudy 配置本地站点的ssl证书
    b
    __invoke,try{}catch(){},microtime(),is_callable()
    json_encode 中文不乱码
    php ::class
    yii 2 美化url
    JNIjw03
  • 原文地址:https://www.cnblogs.com/chenjunbiao/p/1772983.html
Copyright © 2011-2022 走看看