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

推荐订阅源

WordPress大学
WordPress大学
J
Java Code Geeks
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
腾讯CDC
IT之家
IT之家
罗磊的独立博客
酷 壳 – CoolShell
酷 壳 – CoolShell
U
Unit 42
爱范儿
爱范儿
博客园 - 聂微东
F
Fortinet All Blogs
V
Visual Studio Blog
Blog — PlanetScale
Blog — PlanetScale
G
Google Developers Blog
aimingoo的专栏
aimingoo的专栏
L
LangChain Blog
雷峰网
雷峰网
B
Blog RSS Feed
宝玉的分享
宝玉的分享
T
Tailwind CSS Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Engineering at Meta
Engineering at Meta
H
Hackread – Cybersecurity News, Data Breaches, AI and More

博客园 - 小乔的闺房

学习ID,ClientID,UniqueID 基础知识1 (1)将对象序列化为bin,soap,xml (4)迭代器 (3)集合接口 (1)学习数组,集合,IEnumerable接口,引申学习迭代器 (2)学习集合,引申学习索引器和泛型 自定义服务器控件(1)整体把握(未完待续) FindControl实现原理 location详解 使用ASP.NET AJAX实现(图片)幻灯片效果 固定GridView列字符串长度,多于的用...代替 读取Excel数据到GridView相关问题(待完善) 说明nchar(10),char(10),nvarchar(10),varchar(10) syscolumns 获得数据库里所有表的名称 类[属性扩展],属性[属性扩展](待完善) 获得数据库表的列数 WebForm里弹出警告框之内的自定义类MessageBox
(2)最简单的Remoting程序
小乔的闺房 · 2007-11-04 · via 博客园 - 小乔的闺房

(1) 编写3步走
(类库)对象General
(控制台应用程序)服务器端Server:添加对象的dll引用
(控制台应用程序)客户端Client:添加对象的dll引用

(2) 对象
using System;
using System.Collections.Generic;
using System.Text;
namespace RemotingExample
{
    public class Hello : MarshalByRefObject
    {
        public Hello()
        {
            Console.WriteLine("Hello对象被建立");
        }

        public string SayHello(string strClientName)
        {
            return " Hello ! " + strClientName;
        }
    }
}

(3) 服务期端代码
using System;
using System.Collections.Generic;
using System.Text;
//添加的using
using RemotingExample;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
//添加System.Runtime.Remoting引用才能添加以下2个using
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Channels.Http;

namespace RemotingExample
{
    public class Server
    {
        public static int Main(string[] args)
        {
            TcpChannel myTcpChannel = new TcpChannel(8085);//申请tcp通道
            HttpChannel myHttpChannel = new HttpChannel(8086);//申请http通道
            ChannelServices.RegisterChannel(myTcpChannel, false);//注册tcp通道
            ChannelServices.RegisterChannel(myHttpChannel, false);//注册http通道

            RemotingConfiguration.RegisterWellKnownServiceType(
                typeof(Hello),
                "SayHello",
                WellKnownObjectMode.Singleton
                );

            System.Console.WriteLine(" Press Enter key to exit ");
            System.Console.ReadLine();
            return 0;
        }
    }
}

(4) 客户端代码
using System;
using System.Collections.Generic;
using System.Text;
//添加的using
using RemotingExample;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
//添加System.Runtime.Remoting引用才能添加以下2个using
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Channels.Http;

namespace RemotingExample
{
    class Client
    {
        public static int Main(string[] args)
        {
            //使用TCP通道获得远程对象
            TcpChannel myTcpChannel = new TcpChannel();
            ChannelServices.RegisterChannel(myTcpChannel, false);
            Hello myHelloTCP = (Hello)Activator.GetObject(typeof(Hello), "tcp://localhost:8085/SayHello");
            if (myHelloTCP == null)
            {
                System.Console.WriteLine("Could not locate TCP server");
            }
            //使用HTTP通道获得远程对象
            HttpChannel myHttpChannel = new HttpChannel();
            ChannelServices.RegisterChannel(myHttpChannel, false);
            Hello myHelloHTTP = (Hello)Activator.GetObject(typeof(Hello), "http://localhost:8086/SayHello");
            if (myHelloHTTP == null)
            {
                System.Console.WriteLine("Could not locate TCP server");
            }

            //[TCP]调用远程对象的方法
            System.Console.WriteLine("TCP: " + myHelloTCP.SayHello("miclu"));

            //[HTTP]调用远程对象的方法
            System.Console.WriteLine("HTTP: " + myHelloHTTP.SayHello("miclu"));

            System.Console.ReadLine();
            return 0;
        }
    }
}

这样代码就写死了,下节学习使用Remoting配置文件