RSS 2.0 Feed
2006-10 Entries
摘要: 先看一个现象: 如果你有这样的一个WebService 方法: [WebMethod] public void myTest(System.Collections.Specialized.NameValueCollection col) { ..... } 那你在请求这个WebService 方法的时候,会收到如下异常: To be XML serializable, types which inherit from ICollection must have an implementation of Add(System.String) at all levels of their inheritance hierarchy. System.Collections.Specialized.NameValueCollection does not implement Add(System.String). 详细的错误发生点如下: [InvalidOperationException: To be XML serializable, types which inherit from ICollection must have an implementation of Add(System.String) at all levels of their inheritance hierarchy. System.Collections.Specialized.NameValueCollection does not implement Add(System.String).] System.Xml.Serialization.TypeScope.GetDefaultIndexer(Type type,......[阅读全文]

posted @ | Feedback (7) | Filed Under [ .net 编程心得 技术随笔 网站开发管理相关内容 VS2005相关 ]

摘要: 我们使用 FileSystemObject 对象创建文件时候,由于这是个早期版本,你想创建一个utf-8编码的文件,或者读取时候,很容易出现乱码。这时候,你可以使用 ADODB.Stream 对象: 下面的代码就是一个简单的vbScript例子, 把C:\Logs\ 目录下的所有文件和并到一个568.txt 文件: Function LoadFile(Path) Dim Stm2 Set Stm2 = CreateObject("ADODB.Stream") Stm2.Type = 2 Stm2.Mode = 3 Stm2.Open Stm2.LoadFromFile Path 'Stm2.Charset = "UTF-8" 'Stm2.Charset = "Unicode" ......[阅读全文]

posted @ | Feedback (5) | Filed Under [ 技术随笔 网站开发管理相关内容 ]

摘要:Com+ 类的部分代码: namespace TransactUserManage{?[Transaction(TransactionOption.Required)]?public class?TransactUserClass : ServicedComponent?{ ??public TransactUserClass()??{??} ??private string? strDeployName = null;??public string DeployName??{???get???{????return strDeployName;???}???set???{????strDeployName = value;???}??} ??private Hashtable objDataBaseConnStrArr = null ;??public Hashtable DataBaseConnStrArr??{???get???{????return objDataBaseConnStrArr;???}???set???{????objDataBaseConnStrArr = value;???}??} ??private string strCurrUserDataBaseConn = null;??public string CurrUserDataBaseConn??{???get???{????return strCurrUserDataBaseConn;???}???set???{????strCurrUserDataBaseConn = value;???}??}....? 其他代码。 ??public bool ModifyPenName(int iUserID,string strPenName)??{???if (!ContextUtil.IsInTransaction)????throw new Exception("ActivationUser 不支持事务处理!!");???string WhichSolution = strDeployName;????string strUserConn = strCurrUserDataBaseConn;????string strCSDNExpertConn = objDataBaseConnStrArr["CSDN_BBS_ConnStr"].ToString();????string strCSDNLtConn = objDataBaseConnStrArr["CSDN_Main_ConnStr"].ToString(); .... 其他代码} } } } 调用部分 ????TransactUserManage.TransactUserClass obj = new TransactUserClass();????obj.DeployName = ConfigInfoClass.DeployName;????obj.CurrUserDataBaseConn = ConfigInfoClass.CurrUserDataBaseConn;????obj.DataBaseConnStrArr = ConfigInfoClass.DataBaseConnStrCache;????bool result = obj.ModifyPenName(iUserID,strPenName); 这里我确认? ConfigInfoClass.DeployName?? ConfigInfoClass.CurrUserDataBaseConn?? ConfigInfoClass.DataBaseConnStrCache 都是正确的值。 但是进入到??? string strUserConn = strCurrUserDataBaseConn; 这里后, 单步调试 strCurrUserDataBaseConn 的值竟然是 null , 我确定 obj.CurrUserDataBaseConn = ConfigInfoClass.CurrUserDataBaseConn; 这里的 ConfigInfoClass.CurrUserDataBaseConn 是有值的呀。 ?...[阅读全文]

posted @ | Feedback (1) | Filed Under [ .net 编程心得 ServicedComponent(企业服务) ]

摘要:分布式应用如果用 Com+ 来开发的话,一个好处就是,你不用修改任何代码,只需要修改Com+的部署,既可以实现分布式。 下面是就是部署分布式Com+需要注意的一些东西和步骤: 部署要求:有A、B、C 三台机子。A机子是实际 Com+ 应用运行的机子。B、C机子调用A机子的Com+应用。 首先:在A机子部署Com+应用。如果这个应用是基于.net 开发的,只需要简单的执行下面两步:(TopicManage.dll 为假设要部署的Com+应用) gacutil -i TopicManage.dll? (部署到GAC,有些简单的Com+不需要部署到GAC中,后面一个Blog会具体谈到这个问题)RegSvcs TopicManage.dll 在确保本地部署Com+成功后。要进入 Component Services ,去修改已经部署的 Com+ 应用的默认设置。 在 Com+ 应用的属性中,首先需要在它的 Activation 属性中修改 Activation type 为 Server application(Run application as NT Service 的选项无所谓选不选,具体自己决定) 如下图: ? 如果只修改这一项,并保存,这时候启动这个 Com+? Application 会报下面错误: ---------------------------Catalog Error---------------------------You do not have permission to perform the requested action.? If security is enabled on the System Application of the target computer? make sure you are included in the appropriate roles.---------------------------OK?? --------------------------- 你需要修改这个 Com+ Application 的安全设置,在 Security 属性的 Authorization 中,确认 Enforce access checks for this application 这个选项没有被打勾。然后保存设置。启动这个Com+ 应用。这样A 机器的设置就完成了。 如下图: ? 下面我们需要到 B、C 机子安装 对 A 机器Com+ 的引用。 Com+ 应用可以方便的导出为一个安装文件。然后在其他机子上执行这个安装文件,实现其他机子的部署。 选择 A 机器的Com+? 应用,执行导出命令,在导出设置的时候,注意选择 Application proxy - Install on other......[阅读全文]

posted @ | Feedback (21) | Filed Under [ .net 编程心得 ServicedComponent(企业服务) ]

摘要:使用自定义的类,作为函数的参数,可以解决传递参数过多的问题。在Com+ 中使用自定义的类来传递参数,需要注意以下几点: 编码需要注意的:你的自定义的类必须是可以序列化的,当然也可以继承自:? ServicedComponent 类。因为 从 servicedcomponent 继承 就直接有序列化标志了。 比如下面的代码就是正确的: ??? using System;??? namespace ComPlusLib??? {??????? public class WriteFileTest:System.EnterpriseServices.ServicedComponent??????? {??????????? public string SayHello(String s)??????????? {??????????????? System.IO.FileStream fs=new System.IO.FileStream("c:\\t.txt",System.IO.FileMode.Append,System.IO.FileAccess.Write);??????????????? System.IO.StreamWriter sw=new System.IO.StreamWriter(fs);??????????????? sw.WriteLine(s);??????????????? sw.Close();??????????????? fs.Close();??????????????? return System.Diagnostics.Process.GetCurrentProcess().ProcessName + s ;??????????? } ??????????? public string TestObject(Fac1 f)??????????? {??????????????? return f.FullName;??????????? }??????? } ??????? ??????? public class Fac1:System.EnterpriseServices.ServicedComponent??????? {??????????? public string ShowMyProcess()??????????? {??????????????? return System.Diagnostics.Process.GetCurrentProcess().ProcessName;??????????? } ??????????? public string FullName;??????? }??? } 部署需要注意的:在部署这个Com+ 的时候,注意,一定要把编译后的Dll也部署到GAC中。如果你没把这个Dll 部署到GAC,你会获得以下错误信息: Insufficient state to deserialize the object. More information is needed. 满足以上两个条件,你就可以在Com+ 中使用自定义的类作为函数的参数了。 在我的一个程序中,就是没有注意第一点,编写的一个Com+ 没有错误。但是其实他的执行不是走得Com+。 而是直接调用GAC中的函数了。一直到作分布式部署的时候,才发现程序的问题。...[阅读全文]

posted @ | Feedback (9) | Filed Under [ .net 编程心得 技术随笔 ServicedComponent(企业服务) ]

摘要: 企业服务组件类的接口被定义在另外一个项目中可能会出现的一种错误 最近在作的一个项目中,一个企业服务组件要遵循一个接口,类似如下: public class EnterpriseUserDataManager : ServicedComponent,ICommunityUserDataManager 我对 ICommunityUserDataManager 接口的定义在另外一个项目中。 这个接口有好几个函数,如下: public interface ICommunityUserDataManager { CommunityUser GetCommunityUser(string userName); void InsertCommunityUser(CommunityUser user); ......[阅读全文]

posted @ | Feedback (7) | Filed Under [ .net 编程心得 技术随笔 网站开发管理相关内容 VS2005相关 ServicedComponent(企业服务) ]

摘要:今天在写一个企业服务组件,是在一个ClassLibrary项目基础上修改的.这个企业服务中包含很复杂的业务逻辑,其中用到了Singleton 模式来确保只有一个缓存。相关技术参看:http://sajadi.co.uk/dflat/archives/2005/11/creating_a_cach.html 编译时候没有任何问题,然后就是部署,结果部署的时候报下面错误: 出现下列安装错误:1: 在程序集中找到无效的 ServicedComponent 派生类。(类必须是公共的、具体的、有公共的默认构造函数并满足所有其他 ComVisibility 要求) 这个错误信息让我对是否可以在企业服务中使用单键模式产生怀疑。网上也有不少对企业服务使用单键模式的讨论。观点各不相同,结果一下午就迷失在这里了。http://www.pcreview.co.uk/forums/thread-1382837.phphttp://www.pcreview.co.uk/forums/thread-1382837-2.php 一直到快下班,才发现,根本不是上述使用单键模式的问题,而是ClassLibrary项目的AssemblyInfo.cs文件,默认设置是 [assembly: ComVisible(false)] 如果你要做EnterpriseServices,则需要把这个修改为true ,汗颜,最基本的地方给忘掉了。 在AssemblyInfo.cs文件ComVisible上有明确的提示,自己竟然没留意,提示如下: // Setting ComVisible to false makes the types in this assembly not visible // to COM components.? If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type.[assembly: ComVisible(true)]...[阅读全文]

posted @ | Feedback (6) | Filed Under [ .net 编程心得 技术随笔 VS2005相关 ServicedComponent(企业服务) ]

摘要: 我写的一个项目,其中用到COM+(企业服务),今天早上的时候,突然发现项目编译不过去了。报错误: “Error code 80040154 - Class not registered” 细查下去,发现Com+的部署出了问题。 当我打开“Component Services”想看个究竟的时候,发现无法打开了,报错误如下图: “An error occurred while processing the last operation. Error code 80040154 - Class not registered The event log may contain additional troubleshooting information” ......[阅读全文]

posted @ | Feedback (7) | Filed Under [ .net 编程心得 技术随笔 ServicedComponent(企业服务) ]

摘要:比如如下的代码: [assembly: CLSCompliant(true)] public class SiteUrlsData { protected string _locationFilter = null;//路径 public string LocationFilter { get { return _locationFilter; } } } ......[阅读全文]

posted @ | Feedback (6) | Filed Under [ .net 编程心得 技术随笔 VS2005相关 ]

摘要:北京Teched上,我的BOF上,讲话太多,回来就感觉嗓子很难受,很快就由嗓子发炎演变成咳嗽。 我就自己买了一些金嗓子喉宝、西瓜霜润喉片、感冒冲剂等药,但是几天后,症状还没有减轻,反而咳嗽的更加厉害了。尤其是,一旦躺下,很快就会疯狂的咳嗽。 然后我就去看医生,医生给开了300元多的药,阿莫西林、蛇胆川贝等等,就差没去输液。 结果吃了三天也没有好转。 这就已经在十一长假了。我都准备着去医院去输液了。当时心理有很坏的打算,看起来是咳嗽,但是演变成某某重症的又不是没听说过。 当时,一个朋友推荐了一个药,京都念慈蓭密炼川贝枇杷膏。一个很象蜂蜜的药,20多一盒,我只吃了2、3勺,就彻底不咳嗽了。 这件事情让我感慨万千。 为了解决一件事情,我们可能会翻箱倒柜的大动肝火,最后发现,解决这个问题只需轻微的动了一些内容。则一且问题都解决了。我们之前那么多的大动肝火,不能说没有用,但是没有根本解决问题。 看病的问题,我无法发表更多见解,毕竟我不是医生。 在技术方面,其实我们也会碰到很多类似的事情,比如之前,我跟其他部门同事讨论一个开放给他们的接口的问题。结果越讨论需要暴露的东西越多。另外,这还涉及到,加密传输的问题。 最后解决方法是啥呢?? 很简单,我问对方,你要这些数据干么?? 对网站来说,最终也就是展示内容呀,那我就给最终展示的内容算了,这样就可以省略到很多需要传递的数值了。 小结: 换种方法,或者换种思路,解决问题就会变得非常简单。...[阅读全文]

posted @ | Feedback (13) | Filed Under [ 设计思路 非技术随笔 ]

摘要:最近在把一个基于.net 2.0 下的Community Server 2.0 的站点升级到基于.net 2.0 下的Community Server 2.1的时候,碰到了一些小问题, 特整理如下:一、Community Server 2.1 中,基于.net 2.0 和 .net 1.1 的两个配置文件结构不一样的。这两个配置文件如下:Web.configcommunityserver.config而,我们从CommunityServer站点下载到的SDK源代码是基于1.1的,2.0下的文件需要我们自己来修改。 基于.net 1.1 的 Web.config 文件,与基于.net 2.0 的文件,有以下配置节是不一样的,这些不一样的地方,都是.net 2.0 中新提供的一些功能,如下: Community Server 2.1 中使用了.net2.0中才有的一些配置节,这些配置节如下:1、数据库链接配置节 connectionStrings2、Page.EnableEventValidation 配置属性3、machineKey 配置节 4、membership 配置节5、roleManager 配置节6、profile 配置节7、anonymousIdentification 配置节 基于.net 1.1 的 communityserver.config 和 基于.net 2.0 的差别主要是一些实现上的不同:如下,首先是 .net 2.0 下的配置     <add         name = "MemberRoleProfileProvider"        type = "CommunityServer.ASPNet20MemberRole.CSMemberRoleProfileProvider, CommunityServer.ASPNet20MemberRole"    />    <job singleThread = "false" minutes = "5" name = "Emails" type = "CommunityServer.Components.AspNet20EmailJob, CommunityServer.Components" enabled = "true" enableShutDown = "false" failureInterval = "1" numberOfTries = "10" /> 其下是 .net 1.1 下的配置    <add         name = "MemberRoleProfileProvider"        type = "CommunityServer.MemberRole.CSMemberRoleProfileProvider, CommunityServer.MemberRole"    />        <job singleThread = "false" minutes = "5" name =......[阅读全文]

posted @ | Feedback (4) | Filed Under [ .net 编程心得 技术随笔 网站开发管理相关内容 ]