背景:ms有一个叫CCF的东西(记得不止一个人问我怎么没有听说过...其实它被ms藏的很深),是一个用到了Enterprise Library 部分功能的C/S架构的...桌面程序原型。
你能想象这个程序要像sharepoint一样的在不同于开发机的环境去做客户端的部署和调试吗,现在给你一个尽情联想的机会。
你能忍受一个调试时间比web程序还要长的windows程序吗?(个人比较困难)
有没有解决方案?
我正在琢磨...
以下是一个和标题有关的内容,我想大家不用想也知道是70行代码,没有什么特别的地方,每一句都有人看见过。

 1 using System;
 2 using System.Configuration;
 3 using System.Diagnostics;
 4 using System.IO;
 5 using System.Linq;
 6 using System.Reflection;
 7 using System.ServiceModel;
 8 using System.ServiceModel.Configuration;
 9 
10 namespace Eclipse.CCF
11 {
12     class Program
13     {
14         static void Main(string[] args)
15         {
16             LoadAssembliesInExecutingDirtory();
17             var hostTypeList = from ServiceEndpointElement endpoint
18                                    in
19                                    (from ServiceElement service in
20                                         ((ServicesSection)
21                                          ConfigurationManager.GetSection("system.serviceModel/services")).Services
22                                     let Endpoints = service.Endpoints
23                                     select (from ServiceEndpointElement endpoint2 in Endpoints
24                                             where endpoint2.Address.OriginalString.StartsWith("http")
25                                             select endpoint2).First())
26                                select new { Type = FindTypeInRefAssemblies(endpoint.Contract), Uri = endpoint.Address };
27             foreach (var hostType in hostTypeList)
28             {
29                 var serviceHost = new ServiceHost(hostType.Type, hostType.Uri);
30                 serviceHost.Open();
31             }
32             Console.ReadKey();
33         }
34 
35         static void LoadAssembliesInExecutingDirtory()
36         {
37             var assemblies = AppDomain.CurrentDomain.GetAssemblies();
38             foreach(var path in Directory.GetFiles(AppDomain.CurrentDomain.SetupInformation.ApplicationBase))
39             {
40                 if(Path.GetExtension(path).Equals(".dll", StringComparison.CurrentCultureIgnoreCase))
41                 {
42                     if (!assemblies.Any(ass => ass.GetName().Name == Path.GetFileNameWithoutExtension(path)))
43                         try {
44                             Assembly.LoadFile(path); 
45                         }
46                         catch {Debug.Fail("loaded an unknown dll");}
47                 }
48             }
49         }
50 
51         static Type FindTypeInRefAssemblies(string typeName)
52         {
53             Type type = null;
54             
55             Debug.Assert(AppDomain.CurrentDomain.GetAssemblies().Any(ass =>
56                                                             {
57                                                                 if (!ass.FullName.StartsWith("Microsoft.Ccf.Csr.WebServices"))
58                                                                     return false;
59                                                                 type = ass.GetType(typeName);
60                                                                 return type != null;
61                                                             })); ;
62             return type;
63         }
64     }
65 }
66 
67 
68 
69 
70 


弱弱的说,其实这里是没有70行的,为了凑个整数故意在屁股后面补了几个空格。

这样本来构建在IIS下面的WCF已经可以顺利地在一个控制台程序中寄宿,用一个svc试试?非常的成功,可以开香槟了。
注意虽然没有用到一行WS的程序集内的类型,引用的话IDE会自动把相关程序集帮您COPY到目标输出,这样可以非常的明确引用关系。




Feedback

#1楼    回复  引用  查看    

2008-04-25 17:09 by 生鱼片      
这图片太大了,浏览不正常了

#2楼    回复  引用  查看    

2008-04-25 17:09 by 横刀天笑      
发现LZ说话一直在卖关子,至今我也不知道啥是CCF,查了一下只有个Customer Care Framework ,难道是这个?不过这个是客户框架啊,并不是你所说的桌面软件框架

#3楼    回复  引用  查看    

2008-04-25 17:09 by 横刀天笑      
您老就不能给个连接么?。。。。。。。。哎

#4楼 [楼主]   回复  引用  查看    

2008-04-25 17:17 by A.Z      
--引用--------------------------------------------------
横刀天笑: 您老就不能给个连接么?。。。。。。。。哎
--------------------------------------------------------


链接:
http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=1061&SiteID=1

#5楼    回复  引用  查看    

2008-04-26 09:51 by 俺也不懂      

#6楼    回复  引用  查看    

2008-04-27 20:26 by 镜涛      
mark