• 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"给自己打气,努力做到“不抛弃,不放弃”,希望生活一天比一天美好。

  • 相关阅读:
    js 工厂模式、简单模式、抽象模式
    Angular 框架介绍
    Node.js从入门到实战ECMAScript6一页纸总结(很大的一页纸)
    ECMAScript 5和ECMAScript6的新特性以及浏览器支持情况
    JSONP 教程
    jQuery ajax() 方法
    AJAX异步的 JavaScript
    自动化构建工具--gulp的初识和使用
    front-end 前端发展学习路线参考图
    Webpack 常用命令总结以及常用打包压缩方法
  • 原文地址:https://www.cnblogs.com/zhangzheny/p/910859.html
Copyright © 2020-2023  润新知