惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Security Affairs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Jina AI
Jina AI
P
Palo Alto Networks Blog
GbyAI
GbyAI
大猫的无限游戏
大猫的无限游戏
A
Arctic Wolf
Hugging Face - Blog
Hugging Face - Blog
小众软件
小众软件
Y
Y Combinator Blog
T
The Blog of Author Tim Ferriss
Blog — PlanetScale
Blog — PlanetScale
S
Schneier on Security
V
Vulnerabilities – Threatpost
C
Cybersecurity and Infrastructure Security Agency CISA
雷峰网
雷峰网
T
Tenable Blog
人人都是产品经理
人人都是产品经理
T
Tor Project blog
C
Cyber Attacks, Cyber Crime and Cyber Security
AWS News Blog
AWS News Blog
Microsoft Security Blog
Microsoft Security Blog
J
Java Code Geeks
Scott Helme
Scott Helme
SecWiki News
SecWiki News
C
CERT Recently Published Vulnerability Notes
Recorded Future
Recorded Future
I
InfoQ
Security Archives - TechRepublic
Security Archives - TechRepublic
Help Net Security
Help Net Security
Cloudbric
Cloudbric
C
Check Point Blog
Engineering at Meta
Engineering at Meta
TaoSecurity Blog
TaoSecurity Blog
B
Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园_首页
N
News and Events Feed by Topic
云风的 BLOG
云风的 BLOG
MyScale Blog
MyScale Blog
腾讯CDC
量子位
Application and Cybersecurity Blog
Application and Cybersecurity Blog
K
Kaspersky official blog
Vercel News
Vercel News
F
Full Disclosure
T
Troy Hunt's Blog
Forbes - Security
Forbes - Security
S
Security @ Cisco Blogs

博客园 - L.Zhang

RMI框架 自己开发连接池 JDBC访问数据库 MyEclipse下开发Web Service 使用传统的XMLHttpRequest发出Ajax请求 XML CDATA XPath 数据库操作的sql脚本 直接选择排序 直接插入排序 气泡排序 Builder 生成器模式(创建型模式) Abstract Factory 抽象工厂模式(创建型模式) Factory Method 工厂方法模式(创建型模式) Singleton单件模式(创建型模式) 使用Profile Service 服务端如何使用Session 让服务端返回xml 用Get方式访问
.Net Remoting
L.Zhang · 2008-01-24 · via 博客园 - L.Zhang

1,远程对象,必须继承MarshalByRefObject

using System;
using System.Collections.Generic;
using System.Text;namespace RemotingSamples
{
    
//远程对象类型
    public class HelloServer : MarshalByRefObject
    {
        
public HelloServer()
        {
            Console.WriteLine(
"HelloServer activated");
        }
public String HelloMethod(String name)
        {
            Console.WriteLine(
"Server Hello.HelloMethod : {0}", name);
            
return "Hi there " + name;
        }
    }
}

2,服务器端

using System;//命名空间导入
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Channels.Http;namespace RemotingSamples 
{
//服务器类
    public class Server
    {
        
public static int Main(string [] args) 
        {
            
//tcp通道
            TcpChannel chan1 = new TcpChannel(8085);//http通道
            HttpChannel chan2 = new HttpChannel(8086);//注册通道
            ChannelServices.RegisterChannel(chan1);
            ChannelServices.RegisterChannel(chan2);
//服务器端激活
            RemotingConfiguration.RegisterWellKnownServiceType
               (
typeof(HelloServer),           //远程对象类型
                "SayHello",                     //url
                WellKnownObjectMode.Singleton   //唯一实例
                );
            System.Console.WriteLine(
"Press Enter key to exit");
            System.Console.ReadLine();
            
return 0;
        }

    }
}

3,客户端方法

using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Channels.Http;
using System.IO;namespace RemotingSamples 
{
    
public class Client
    {
        
public static void Main(string[] args)
        {
           
            
//使用TCP通道得到远程对象
            TcpChannel chan1 = new TcpChannel();
            ChannelServices.RegisterChannel(chan1);
           
            HelloServer obj1 
= (HelloServer)Activator.GetObject(
                
typeof(RemotingSamples.HelloServer),
                
"tcp://localhost:8085/SayHello");
           
            
if (obj1 == null)
            {
                System.Console.WriteLine(
                    
"Could not locate TCP server");
            }
//使用HTTP通道得到远程对象
            HttpChannel chan2 = new HttpChannel();
            ChannelServices.RegisterChannel(chan2);
            HelloServer obj2 
= (HelloServer)Activator.GetObject(
                
typeof(RemotingSamples.HelloServer),
                
"http://localhost:8086/SayHello");
            
if (obj2 == null)
            {
                System.Console.WriteLine(
                    
"Could not locate HTTP server");
            }
//调用远程方法
            Console.WriteLine(
                
"Client1 TCP HelloMethod {0}",
                obj1.HelloMethod(
"Caveman1"));
            Console.WriteLine(
                
"Client2 HTTP HelloMethod {0}",
                obj2.HelloMethod(
"Caveman2"));
            Console.ReadLine();
        }
    }
}