首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

在C/S三层架构中怎么使用Remoting技术

2012-03-03 
在C/S三层架构中如何使用Remoting技术?Remoting服务端配置文件?xmlversion 1.0 encoding utf-8 ?c

在C/S三层架构中如何使用Remoting技术?
Remoting服务端配置文件
?xml   version= "1.0 "   encoding= "utf-8 "   ?>
<configuration>
    <configSections>
        <section   name= "DbConfig "   type= "DataAccess.ConfigurationHandler,   DataAccess "/>
    </configSections>
    <system.runtime.remoting>
        <application>
            <service>
              <wellknown  
                      mode= "Singleton "   type= "LIMIS_Login.UserLogin,LIMIS_Login "   objectUri= "UserLogin.Soap "   />    
            </service>
            <channels>
                <channel   ref= "tcp "   port= "8000 "/>
                <serverProviders>
                    <formatter   ref= "binary "   typeFilterLevel= "Low "   />
                </serverProviders>
            </channels>
            <lifetime   leaseTime= "5S "   sponsorShipTimeout= "1S "   renewOnCallTime= "2S "   leaseManagerPollTime= "2S "   />
        </application>
    </system.runtime.remoting>
    <DbConfig>
        <Class   name= "Data   Source "   value= "localhost "/>
        <Class   name= "Initial   Catalog "   value= "LIMIS "/>
        <Class   name= "Integrated   Security "   value= "True "/>
       
    </DbConfig>
</configuration>
客户端配置文件
<configuration>
    <configSections>
        <section   name= "system "   type= "Host.ConfigureHandler,   Host "/>
        <section   name= "Framework "   type= "Host.ConfigureHandler,   Host "/>
          </configSections>
    <system>
        <Server   location= "localhost "   port= "8000 "   />
    </system>
    <Framework>    
    <Class   name= "ILIMIS_Login "   location= "UserLogin.Soap "   type= "ILIMIS_Login.IUserLogin,ILIMIS_Login "/>  
    </Framework>
</configuration>

我在使用以下代码激活的时候不能获得相应接口的类型,请高手指点指点,小弟现在做毕业设计,急啊!这个问题不解决,就做不了了。
public   static   object   getInterface(string   IName)
                {
                        object   returnObj;
                        try


                        {
                                string   format   =   "tcp://{0}:{1}/{2} ";
                                RemotingConfiguration.Configure( "WindowsApplication1.exe.config ");                              

                                object   obj   =   ConfigurationSettings.GetConfig( "Framework ");
                                XmlNode   node   =   ((XmlNode)ConfigurationSettings.GetConfig( "Framework ")).SelectSingleNode( "Class[@name= ' "   +   IName.Trim()   +   " '] ");
                                if   (node   ==   null)
                                {
                                        throw   new   Exception( "没有找到   "   +   IName.Trim()   +   "   接口的相关配置信息 ");
                                }
                                Type   type   =   Type.GetType(node.Attributes[ "type "].Value);
                                if   (type   ==   null)
                                {
                                        throw   new   Exception( "没有获得  "   +   IName.Trim()   +   "   接口的类型 ");
                                }                                
                                string   txt   =   node.Attributes[ "location "].Value;
                                format   =   string.Format(format,   new   object[]   {   data,   num,   txt   });
                                returnObj   =   Activator.GetObject(type,   format);
                        }
                        catch   (Exception   exception)
                        {


                                throw   exception;
                        }
                        return   returnObj;

                }

初步想法是,后台实现访问数据功能,并提供一个interface供前台调用,现难点是激活服务对象出了问题,请高手指点,小弟在此不胜感激!



[解决办法]
ref:
http://www.webstudy8.com/web/net/218/0652006550153155.html
[解决办法]
.NET 远程处理为进程间通信提供了一种抽象的方法,它将可远程处理的对象与特定客户端或服务器应用程序域以及特定的通信机制隔离开来。因此,这很灵活且很容易自定义。可以用一种通信协议替换另一种通信协议,或者用一种序列化格式替换另一种序列化格式,而不必重新编译客户端或服务器。此外,远程处理系统假定没有特别的应用程序模型。可以从 Web 应用程序、控制台应用程序、Windows 服务,即差不多可以从希望使用的任何程序中进行通信。远程处理服务器也可以是任何类型的应用程序域。任何应用程序都可以承载远程处理对象并向其计算机或网络上的任何客户端提供服务。
System.Runtime.Remoting 命名空间提供允许开发人员创建和配置分布式应用程序的类和接口。System.Runtime.Remoting 命名空间的一些更重要的类是 RemotingConfiguration 类、RemotingServices 类和 ObjRef 类。
RemotingConfiguration 类包含用于与配置设置衔接的静态方法。RemotingConfiguration.Configure 方法允许开发人员通过使用 XML 格式化配置文件来配置远程处理基础结构。RemotingConfiguration 类还包含若干在客户端和服务器端注册驻留在服务器上的客户端激活对象和服务器端激活对象的方法。
RemotingServices 类提供若干帮助使用和发布远程对象的方法。System.Runtime.Remoting.RemotingServices.Marshal 方法提供在 ObjRef 类的实例中存储激活远程对象并与之通信所需的所有相关信息供以后序列化和传输到远程位置使用的功能。System.Runtime.Remoting.RemotingServices.Unmarshal 方法反转此过程,为远程对象创建可由应用程序使用的代理,不考虑任何远程处理分支。
ObjRef 类保存激活远程对象并与之通信所需的所有相关信息。该类是通过信道传输到远程位置的对象的序列化表示形式,在信道中它被取消封送(请参见 Unmarshal)并可用于创建远程对象的本地代理。

以上这些都是MSDN的资料,要学会看MSDN。

[解决办法]
楼主的代码很奇怪,为什么要这样写?
你去看看MSDN,那里有例子!

热点排行