Montaque & DotNet

你是不是在阳光下低头, 流着汗水默默的辛苦工作

导航

<2012年5月>
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789

公告

档案

随笔分类

相册

登录

统计

Biztalk

BLOG

DotNet

DotNet Remoting

InfoPath And SPS

生活在上海

2004年8月25日 #

.NET 三种 序列化方式

1。 XML Serializer。这个是 ASP。NET 中 Web Service SOAP 请求的发送和接受默认使用的方式。指序列化对象的公共属性和成员。

2。 SOAP Serializer . DotNet Remoting 使用的对象传送方式。这个时候传送的对象要求有 Serializable 标志。

3.    BinarySerializer 。同2, 只不过是二进制格式。

 

代码示例:

考虑一个 Person 对象,会有一些属性比如fullname,唯一 ID,电话(最多三个。)

 

[Serializable]
 public class Phone
 {
  private string _phoneNumber="";
  private string _phoneType="";
  public Phone(string phoneType,string phoneNumner)
  {
   _phoneNumber=phoneNumner;
   _phoneType=phoneType;
  }

  public string PhoneDescp
  {
   get
   {
    return string.Format("{0}\t{1}",_phoneType,_phoneNumber);

   
    
   }
  }

  public Phone()
  {

  }
 }

 

[Serializable]
 public class Person
 {
  public Person()
  {
   //
   // TODO: 在此处添加构造函数逻辑
   //
  }

 

  //电话列表假设只能最多有三个
  private Phone []  _allPhones=new Phone[3];
 
  //全称
  private string fullName="";
  
  //唯一的标识
  private System.Guid id=System.Guid.NewGuid();


  public string FullName
  {
   get{return fullName;}
   set{fullName=value;}
  }

  /// <summary>
  /// 标识
  /// </summary>
  public System.Guid ID
  {
   get
   {
    return id;
   }
  
  }

  public Phone this[int phoneIndex]
  {
   
   get
   {
    System.Diagnostics.Debug.Assert(phoneIndex>=0 && phoneIndex<=2);
    return _allPhones[phoneIndex];
   }
   set
   {
    System.Diagnostics.Debug.Assert(phoneIndex>=0 && phoneIndex<=2);
    _allPhones[phoneIndex]=value;
   }
  }

 

 }

 

如果用 XML Serializer

只能看到一下结果。只序列华了 fullname

---------------------------

---------------------------
<?xml version="1.0" encoding="utf-16"?>

<Person xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

  <FullName>MontaqueHou</FullName>

</Person>
---------------------------
OK  
---------------------------

注意 GUID 和 Phone 都没有序列化。长度为195 个字节。

 

而采用 SOAP 序列华则序列化了所有,2022 个字节。

---------------------------

---------------------------
<SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:clr="http://schemas.microsoft.com/soap/encoding/clr/1.0" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">

<SOAP-ENV:Body>

<a1:Person id="ref-1" xmlns:a1="http://schemas.microsoft.com/clr/nsassem/Comparation/Comparation%2C%20Version%3D1.0.1698.18683%2C%20Culture%3Dneutral%2C%20PublicKeyToken%3Dnull">

<_allPhones href="#ref-3"/>

<fullName id="ref-4">MontaqueHou</fullName>

<id>

<_a>120451046</_a>

<_b>-8025</_b>

<_c>17783</_c>

<_d>155</_d>

<_e>187</_e>

<_f>62</_f>

<_g>53</_g>

<_h>99</_h>

<_i>190</_i>

<_j>9</_j>

<_k>169</_k>

</id>

</a1:Person>

<SOAP-ENC:Array id="ref-3" SOAP-ENC:arrayType="a1:Phone[3]" xmlns:a1="http://schemas.microsoft.com/clr/nsassem/Comparation/Comparation%2C%20Version%3D1.0.1698.18683%2C%20Culture%3Dneutral%2C%20PublicKeyToken%3Dnull">

<item href="#ref-5"/>

<item href="#ref-6"/>

<item href="#ref-7"/>

</SOAP-ENC:Array>

<a1:Phone id="ref-5" xmlns:a1="http://schemas.microsoft.com/clr/nsassem/Comparation/Comparation%2C%20Version%3D1.0.1698.18683%2C%20Culture%3Dneutral%2C%20PublicKeyToken%3Dnull">

<_phoneNumber id="ref-8">13817327101-000</_phoneNumber>

<_phoneType id="ref-9">Type 1</_phoneType>

</a1:Phone>

<a1:Phone id="ref-6" xmlns:a1="http://schemas.microsoft.com/clr/nsassem/Comparation/Comparation%2C%20Version%3D1.0.1698.18683%2C%20Culture%3Dneutral%2C%20PublicKeyToken%3Dnull">

<_phoneNumber id="ref-10">13817327101-001</_phoneNumber>

<_phoneType href="#ref-9"/>

</a1:Phone>

<a1:Phone id="ref-7" xmlns:a1="http://schemas.microsoft.com/clr/nsassem/Comparation/Comparation%2C%20Version%3D1.0.1698.18683%2C%20Culture%3Dneutral%2C%20PublicKeyToken%3Dnull">

<_phoneNumber id="ref-11">13817327101-002</_phoneNumber>

<_phoneType href="#ref-9"/>

</a1:Phone>

</SOAP-ENV:Body>

</SOAP-ENV:Envelope>


---------------------------
OK  
---------------------------

Binary 也序列华了所有属性。517 个字节

---------------------------

---------------------------
00-01-00-00-00-FF-FF-FF-FF-01-00-00-00-00-00-00-00-0C-02-00-00-00-49-43-6F-6D-70-61-72-61-74-69-6F-6E-2C-20-56-65-72-73-69-6F-6E-3D-31-2E-30-2E-31-36-39-38-2E-31-38-36-38-33-2C-20-43-75-6C-74-75-72-65-3D-6E-65-75-74-72-61-6C-2C-20-50-75-62-6C-69-63-4B-65-79-54-6F-6B-65-6E-3D-6E-75-6C-6C-05-01-00-00-00-12-43-6F-6D-70-61-72-61-74-69-6F-6E-2E-50-65-72-73-6F-6E-03-00-00-00-0A-5F-61-6C-6C-50-68-6F-6E-65-73-08-66-75-6C-6C-4E-61-6D-65-02-69-64-04-01-03-13-43-6F-6D-70-61-72-61-74-69-6F-6E-2E-50-68-6F-6E-65-5B-5D-02-00-00-00-0B-53-79-73-74-65-6D-2E-47-75-69-64-02-00-00-00-09-03-00-00-00-06-04-00-00-00-0B-4D-6F-6E-74-61-71-75-65-48-6F-75-04-FB-FF-FF-FF-0B-53-79-73-74-65-6D-2E-47-75-69-64-0B-00-00-00-02-5F-61-02-5F-62-02-5F-63-02-5F-64-02-5F-65-02-5F-66-02-5F-67-02-5F-68-02-5F-69-02-5F-6A-02-5F-6B-00-00-00-00-00-00-00-00-00-00-00-08-07-07-02-02-02-02-02-02-02-02-E6-EF-2D-07-A7-E0-77-45-9B-BB-3E-35-63-BE-09-A9-07-03-00-00-00-00-01-00-00-00-03-00-00-00-04-11-43-6F-6D-70-61-72-61-74-69-6F-6E-2E-50-68-6F-6E-65-02-00-00-00-09-06-00-00-00-09-07-00-00-00-09-08-00-00-00-05-06-00-00-00-11-43-6F-6D-70-61-72-61-74-69-6F-6E-2E-50-68-6F-6E-65-02-00-00-00-0C-5F-70-68-6F-6E-65-4E-75-6D-62-65-72-0A-5F-70-68-6F-6E-65-54-79-70-65-01-01-02-00-00-00-06-09-00-00-00-0F-31-33-38-31-37-33-32-37-31-30-31-2D-30-30-30-06-0A-00-00-00-06-54-79-70-65-20-31-01-07-00-00-00-06-00-00-00-06-0B-00-00-00-0F-31-33-38-31-37-33-32-37-31-30-31-2D-30-30-31-09-0A-00-00-00-01-08-00-00-00-06-00-00-00-06-0D-00-00-00-0F-31-33-38-31-37-33-32-37-31-30-31-2D-30-30-32-09-0A-00-00-00-0B
---------------------------
OK  
---------------------------

看了这个结果你就明白DotNEt remoting 的优越性了。hh

 

 

10:17 | 评论 (4)

2004年8月19日 #

循环创建 SQL Server 的列.

declare @para  int
set @para=1
declare @k varchar(20),@sql varchar(50)
while @para<9
begin
set @k='p'+ convert(varchar,@para)
print @k
set @sql='alter table test2 add  '  + @k + ' int '
print @sql
execute (@sql)
set @para=@para+1
end

8:45 | 评论 (0)

2004年8月10日 #

C# Code Review Checklist

    摘要:C# Code Review Checklist, 总共39条. 涵盖面比较广,但不是特别的全面.    (全文共10164字)——点击此处阅读全文

13:36 | 评论 (0)

2004年8月4日 #

Microsoft Enterprise Instrumentation Spec.

Download Location: http://www.microsoft.com/downloads/details.aspx?FamilyId=80DF04BC-267D-4919-8BB4-1F84B7EB1368&displaylang=en

“企业规范框架”(EIF) 将解决构建分布式应用程序时遇到的一个关键难题:在高容量的生产环境中实现有效的监视和故障排查。EIF 将提供一个一致、简单的应用程序编程接口 (API) 和配置层,以统一内置于 Windows 中的现有的事件记录和跟踪机制。这将使开发人员能够发布由支持和操作小组监视和分析的审计、错误、警告、业务事件和诊断事件。这些现有的和新的开发人员功能将让使用 Visual Studio .NET 的企业客户变得更高效,同时还可以降低部署成本。

11:53 | 评论 (1)

2004年8月3日 #

ASP.NET Security: 8 Ways to Avoid Attack

http://www.devx.com/security/Article/20898/0/page/1

不错的一片文章.

 

15:59 | 评论 (0)

2004年7月30日 #

分享一个关于水晶报表的技巧.

要解决的问题: 让报表显示的时候不显示 默认的 ToolTip Hint.
比如:
 
解决办法:
目前好像还是一个小的bug, 只能对每个文本框设置.
1. 起始水晶报表中又很多可自定义的东西, 可以自定义的地方一般会有一个 X-2 的标志, 这里面可以写自定义函数逻辑.
 
2. 解决上述问题的办法就是选择工具提示文字 右边的自定义按钮,输入一个他无法显示的字符 CHR(9) 起始就是tab 键. 然后就ok了.
 
 
 

8:58 | 评论 (1)

2004年7月21日 #

Submitting default buttons when the user presses the Enter key

Cause:

http://www.allasp.net/enterkey.aspx

solution

 onkeypress="javascript:return(event.keyCode!=13)"

13:08 | 评论 (1)

2004年7月19日 #

4 Communication Options

When you design your smart client application, you can choose from a number of methods to connect it to other resources, including:

  • Microsoft® .NET Enterprise Services.
  • Microsoft .NET remoting.
  • Microsoft Windows® Message Queuing (also known as MSMQ).
  • Web services.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag/html/scag-ch03.asp

11:19 | 评论 (0)

2004年7月15日 #

SQL SERVER BPA

还既不记得以前发过一个框架警察, http://www.gotdotnet.com/team/fxcop/ , 框架警察会扫描你写好的 assembly 就性能,命名规范, 安全,com 异构应用方面是不是满足规范
 
如果你对安全比较在意的话,微软有一个msba http://www.microsoft.com/technet/security/tools/mbsahome.mspx 可以扫描系统的安全漏洞
 
同样,对于 SQL Server 2000 , 微软最近也推出了一个扫描工具 BPA
 
他主要扫描数据库,包括其中的任何对象, 有没有采取一个好的规范,比如 SELECT 一般不用 * , 写 TOP 需要加上order 等做一个检查, 里面默认自带了很多规则
关于这个工具, 微软有一个 视频的介绍.
http://msdn.microsoft.com/msdntv/episode.aspx?xml=episodes/en/20040610sqlserverck/manifest.xml
 
这个工具的下载地址:
http://www.microsoft.com/downloads/details.aspx?FamilyId=B352EB1F-D3CA-44EE-893E-9E07339C1F22&displaylang=en
 

11:06 | 评论 (2)

.NET Framework 1.1 SP1 Technical Preview

如果你的应用是 基于 .NET Framework 的. 最近微软发布了 .NET Framework 1.0 SP3 和 1.1 SP1 的priview 版本.
http://msdn.microsoft.com/netframework/downloads/updates/sptechpreview/default.aspx
 
关于1.1 修复的内容列表, 如果你的程序有以下链接中的现象, 不放安装一个 sp 试验一下.
http://msdn.microsoft.com/netframework/downloads/updates/sptechpreview/content11sp1.aspx
 
 
注意: 这个只是 priview 版本, 不要用于 production 环境中.

9:52 | 评论 (0)

2004年7月8日 #

Obfuscusion 的介绍.

http://www.simonrobinson.com/DotNET/Articles/Security/Obfuscation1.aspx

 

文章写的还是很不错.

 

15:34 | 评论 (0)

2004年7月5日 #

编辑水晶报表时,工具栏上“切换字段视图”无效

碰到这个问题的时候,系统重装一般没有什么用

有以下几种方案可以解决这个问题

  1. 选择 视图-> 其他窗体-> 文档大纲
  2. 或者新建一个用户登录.

这样一般能解决问题.

10:45 | 评论 (5)

CR.NET For VS.NET 2003 SP2

Crystal Reports for Visual Studio .NET 2003 - NEW - released April 2004 (only for Visual Studio .NET 2003)

Service pack 2 - EXE 7MB

Service pack readme - PDF 89KB

 

English Merge Modules for Crystal Reports for Visual Studio .NET 2003

 

This file contains the latest merge modules required for deploying .NET applications using Crystal Reports for Visual Studio .NET 2003. These merge modules may be incorporated into MSI-based setup packages to include the appropriate runtime files.

published : 2004-4-29

10:18 | 评论 (0)

2004年7月3日 #

BizTalk 2004 Trick: Macros for Constructing Filenames in Files Send Handler

文件的构造,除了 %MessageId% 之外,还有几个可以选择

The following table lists the supported macros and describes how the File send handler substitutes them.

Macro name Substitute value
%datetime% Coordinated Universal Time (UTC) date time in the format YYYY-MM-DDThhmmss (for example, 1997-07-12T103508).
%datetime_bts2000% UTC date time in the format YYYYMMDDhhmmsss, where sss means seconds and milliseconds (for example, 199707121035234 means 1997/07/12, 10:35:23 and 400 milliseconds).
%datetime.tz% Local date time plus time zone from GMT in the format YYYY-MM-DDThhmmssTZD, (for example, 1997-07-12T103508+800).
%DestinationParty% Name of the destination party. The value comes from the message context property BTS.DestinationParty.
%DestinationPartyQualifier% Qualifier of the destination party. The value comes from the message context property BTS.DestinationPartyQualifier.
%MessageID% Globally unique identifier (GUID) of the message in BizTalk Server. The value comes directly from the message context property BTS.MessageID.
%SourceFileName% Name of the file from where the File adapter read the message. The file name includes the extension and excludes the file path, for example, Sample.xml. When substituting this property, the File adapter extracts the file name from the absolute file path stored in the FILE.ReceivedFileName context property. If the context property does not have a value, for example, if a message was received on an adapter other than the File adapter, the macro will not be substituted and will remain in the file name as is (for example, C:\Drop\%SourceFileName%).
%SourceParty% Name of the source party from which the File adapter received the message.
%SourcePartyQualifier% Qualifier of the source party from which the File adapter received the message.
%time% UTC time in the format hhmmss.
%time.tz% Local time plus time zone from GMT in the format hhmmssTZD (for example, 124525+530).

14:36 | 评论 (0)

2004年6月30日 #

Set background color of a treeview

Use the SendMessage API function to send the control the TVM_SETBKCOLOR message. Then reset a few style bits needed by the TreeView control.
 
Private Sub ChangeBackgroundColor(ByVal hWnd As Long, ByVal _
    longColor As Long)
Dim longStyle As Long

    SendMessage hWnd, TVM_SETBKCOLOR, 0, ByVal _
        TranslateColor(longColor)

    ' Reset style so lines display properly (for TreeView
    ' control only)
    longStyle = GetWindowLong(hWnd, GWL_STYLE)
    SetWindowLong hWnd, GWL_STYLE, _
        longStyle And (Not TVS_HASLINES)
    SetWindowLong hWnd, GWL_STYLE, longStyle
End Sub

21:06 | 评论 (0)


请不要发表可能给我们带来伤害的政治言论,谢谢配合