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



 

 

 

posted @ 2010-07-07 16:49  chenjunbiao  阅读(376)  评论(0编辑  收藏  举报