zoukankan      html  css  js  c++  java
  • ipc的remoting

    远程对象:

    using System;
    using System.Collections.Generic;
    using System.Text;

    namespace Object
    {
        
    public class MyObject : MarshalByRefObject
        {
            
    public int Add(int a, int b)
            {
                
    return a + b;
            }
        } 

    }

    1、配置文件方式

    服务端:
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Runtime.Remoting;

    namespace Server
    {
        
    class Program
        {
            
    static void Main(string[] args)
            {
                RemotingConfiguration.Configure(
    "Server.exe.config");
                Console.ReadLine();

            }
        }
    }

    服务端配置文件:
    <configuration>
        
    <system.runtime.remoting>
            
    <application name="RemoteServer">
                
    <service>
                    
    <wellknown type="Object.MyObject,Object" objectUri="Object.MyObject" mode="Singleton" />
                
    </service>
                
    <channels>
                    
    <channel ref="ipc" portName="testPipe" />
                
    </channels>
            
    </application>
        
    </system.runtime.remoting>
    </configuration>

    客户端:
    using System;
    using System.Collections.Generic;
    using System.Text;

    namespace Client
    {
        
    class Program
        {
            
    static void Main(string[] args)
            {
                Object.MyObject app 
    = (Object.MyObject)Activator.GetObject(typeof(Object.MyObject), "ipc://testPipe/Object.MyObject");
                Console.WriteLine(app.Add(
    12));
                Console.ReadLine();

            }
        }
    }

    2、代码方式

    服务端:

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Runtime.Remoting.Channels.Ipc; 
    using System.Runtime.Remoting.Channels;
    using System.Runtime.Remoting;

    namespace Server
    {
        
    class Program
        {
            
    static void Main(string[] args)
            {
                IpcChannel ipcCh 
    = new IpcChannel("testPipe");
                ChannelServices.RegisterChannel(ipcCh);
                RemotingConfiguration.RegisterWellKnownServiceType
                   (
    typeof(Object.MyObject), "Object.MyObject", WellKnownObjectMode.Singleton);
                Console.ReadLine();

            }
        }
    }

    客户端和配置文件方式相同
  • 相关阅读:
    vue.js 条件与循环
    vue.js 声明式渲染
    数据库设计范式?
    用户购物车,实现添加商品的功能!
    用户购物车功能的实现。
    初始ajax技术
    SQL语句中 INNER JOIN的用法!
    商城 用户登录、注册、注销,购物车。
    EL和 JSTL? 在JSP中简化 java代码的写法!
    小数点后保留2位小数的正则表达式
  • 原文地址:https://www.cnblogs.com/lovecherry/p/582927.html
Copyright © 2011-2022 走看看