zoukankan      html  css  js  c++  java
  • 重温.NET Remoting(二)

    这节来谈谈关于Remoting的简单配置

    服务端配置

    <?xml version="1.0"?>
    <configuration>
      
    <system.runtime.remoting>
        
    <application>
          
    <channels>
            
    <channel ref="tcp" port="9999"/>
          
    </channels>
          
    <service>
            
    <wellknown mode="Singleton" type="Server.MyServiceImpl,Server" objectUri="myservice.rem"/>
          
    </service>
        </application>
      
    </system.runtime.remoting>
    </configuration>

    服务端调用

    RemotingConfiguration.Configure("Server.exe.config",false);
                Console.WriteLine(
    "Server is Running...");

    当服务开启后,可以通过控制台查看端口是否开始监听,运行-》cmd-》netstat -a ,通过查看命令显示的信息,判断你所设置的服务是否开启

    客户端配置

    <?xml version="1.0"?>
    <configuration>
      
    <system.runtime.remoting>
        
    <application>
          
    <channels>
            
    <channel ref="tcp"/>
          
    </channels>
          
    <client>
            
    <wellknown type="ShareDLL.IMyService,ShareDLL" url="tcp://localhost:9999/myservice.rem"/>
          
    </client>
        
    </application>
      
    </system.runtime.remoting>
    </configuration>

    客户端调用

     RemotingConfiguration.Configure("Client.exe.config"false);
                WellKnownClientTypeEntry[] types 
    = RemotingConfiguration.GetRegisteredWellKnownClientTypes();
                
    if (types.Length > 0)
                {
                    ShareDLL.IMyService service 
    = (ShareDLL.IMyService)Activator.GetObject(types[0].ObjectType,
                        types[
    0].ObjectUrl);
                    
    try
                    {
                        Console.WriteLine(service.SayHello(
    "mike"));
                    }
                    
    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
                
    else
                    Console.WriteLine(
    "no service reigstered");

    更多关于Remoting的配置,可以参考其他

    作者:Jackhuclan
    出处:http://jackhuclan.cnblogs.com/
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    Linux网络编程一站式学习
    quick-cocos2d-x教程8:程序框架内lib文件夹分析
    petshop4.0 具体解释之中的一个(系统架构设计)
    LNK快捷方式漏洞利用方式 exp制作教程
    Serializable 作用
    0 1背包模板
    跟着辛星认识一下PHP的自己主动载入
    海茶3 らぶデス3 入门经典教程
    win下vm10+mac os 10.9安装遇到问题
    enum 在c中的使用
  • 原文地址:https://www.cnblogs.com/jackhuclan/p/2137756.html
Copyright © 2011-2022 走看看