RemotingIIS承载方式 - 中国WEB开发者网络 (http://www.webasp.net) -- 技术教程 (http://www.webasp.net/article/) --- RemotingIIS承载方式 (http://www.webasp.net/article/28/27646.htm) |
| -- 作者:未知 -- 发布日期: 2006-05-16 |
| 这里来说一下iis承载方式,顺便简单说一下remoting的通道和【复杂对象】中的遗留问题。 首先明确一点:iis来承载的话只能是http通道方式的。 我们来建立一个web项目,比如叫remoting,删除项目中的所有webform,把远程对象dll-RemoteObject.dll复制到项目的dll文件夹下面,然后打开web.config进行服务端设置: <configuration> <appSettings> <add key="strconn" value="server=(local);uid=sa;pwd=;database=UBISOFT" /> </appSettings> <system.runtime.remoting> <application> <service> <wellknown type="RemoteObject.MyObject,RemoteObject" objectUri="MyObject.soap" mode="SingleCall" /> </service> <channels> <channel ref="http"/> </channels> </application> </system.runtime.remoting> </configuration> 来分析一下这个config: <configuration> <appSettings> <add key="ServiceURL" value="http://localhost/remoting/MyObject.soap"/> </appSettings> </configuration> iis承载方式默认是80端口,我们不需要在端口上做任何设置。还需要注意到的是iis方式,我们使用这样的格式作为地址: <configuration> <system.runtime.remoting> <application name="RemoteServer"> <service> <wellknown type="RemoteObject.MyObject,RemoteObject" objectUri="RemoteObject.MyObject" mode="Singleton" /> </service> <channels> <channel ref="tcp" port="9999"/> <serverProviders> <provider ref="wsdl" /> <formatter ref="soap" typeFilterLevel="Full" /> <formatter ref="binary" typeFilterLevel="Full" /> </serverProviders> </channels> </application> </system.runtime.remoting> </configuration> 当然也可以用程序进行设置: using System; using System.Collections; using System.Runtime.Remoting; using System.Runtime.Remoting.Channels; using System.Runtime.Remoting.Channels.Tcp; using System.Runtime.Serialization.Formatters;RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemoteObject.MyObject), "RemoteObject.MyObject", WellKnownObjectMode.Singleton); BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider(); BinaryClientFormatterSinkProvider clientProvider = new BinaryClientFormatterSinkProvider(); serverProvider.TypeFilterLevel = TypeFilterLevel.Full; IDictionary props = new Hashtable(); props["port"] = 9999; TcpChannel channel = new TcpChannel(props,clientProvider,serverProvider); ChannelServices.RegisterChannel(channel); Console.ReadLine(); 客户端还要用程序进行调整: 若要使用配置文件设置反序列化级别,必须显式指定 <formatter> 元素的 typeFilterLevel 属性。虽然这通常是在服务器端指定的,但您还必须为注册来侦听回调的客户端上的任何信道指定这一属性,以控制其反序列化级别 在程序前面加上和服务端基本相同的代码: BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider(); BinaryClientFormatterSinkProvider clientProvider = new BinaryClientFormatterSinkProvider(); serverProvider.TypeFilterLevel = TypeFilterLevel.Full; IDictionary props = new Hashtable(); props["port"] = 0; TcpChannel channel = new TcpChannel(props,clientProvider,serverProvider); ChannelServices.RegisterChannel(channel); 这样就可以了,注意:如果在同一个机器上面测试端口号应设为不同于服务器端设置的端口号,推荐设置为0(远程处理系统自动选择可用端口) • 若要对客户端进行身份验证,请使用 HTTP 通道,在 ASP.NET 中驻留对象,以及在 IIS 中禁用匿名访问。 |
| webasp.net |