豆包ko 发表于 2015-8-12 12:58:57

Remoting服务集成到IIS的简单总结

  因为项目的Remoting服务有可能集成到IIS中,所以下午利用一些时间,做了一个例子,实现了需要的功能,代码就凑合一下。
现在把这个过程总结一下:

1.       创建远程对象类Class1,它实现一个接口Interface1

public class Class1 : MarshalByRefObject, Interface1
    {
      #region Interface1 Members
      public string SendMessage(string msg)
      {
            return "Hello " + msg;
      }
      #endregion
       public override object InitializeLifetimeService()
      {
            return null;
      }
    }
    public interface Interface1
   {
      string SendMessage(string msg);
    }
  2.      建立虚拟目录



根据自己的需要选择选项,我是偷懒,不想受什么限制。生活中已经受到很多限制,难道在自己的机器上做开发还要收到限制吗?


  在F:\IISTest目录下建立Bin目录,然后将包含远程对象类的组件IISClassLibrary1.dll放入bin目录中。并创建Web.config
<system.runtime.remoting>
    <application>
      <service>
      <wellknownmode="Singleton"
                   type="IISClassLibrary1.Class1,IISClassLibrary1"
                   objectUri="Class1.soap"/>
      </service>
   <channels>
      <channel
         name="MyChannel"
         priority="100"
         ref="http"
            />
      </channels>
    </application>
</system.runtime.remoting>
  3.      建立客户端
  使用配置文件,创建App.config配置文件

<?xmlversion="1.0"encoding="utf-8" ?>
<configuration>
<system.runtime.remoting>
    <application>
   <client>
       <wellknowntype="IISClassLibrary1.Class1,IISClassLibrary1"
                   url="http://localhost/IISTest/Class1.soap"/>
      </client>
    </application>
</system.runtime.remoting>
</configuration>


            //客户端调用
            string filename = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
            RemotingConfiguration.Configure(filename,false);
            IISClassLibrary1.Interface1 mgr = new IISClassLibrary1.Class1();            
            string retValue = mgr.SendMessage("yiping");

              获得所需要的结果:Hello yiping

    用“Hello yiping"给自己打气,努力做到“不抛弃,不放弃”,希望生活一天比一天美好。
页: [1]
查看完整版本: Remoting服务集成到IIS的简单总结