zoukankan      html  css  js  c++  java
  • Tcp服务测试工具

    服务端配置文件

     <system.runtime.remoting>
        <application>
          <service>
            <!--SingleCall activated wellknown-->
            <wellknown
               mode="Singleton" 
               type="Capinfo.BJMedicare.HospitalComponent.Service.CenterServer.CallProxy.RemotingService.ProxyObject,
    HCS.CenterServer.CallProxy.RemotingService"
               objectUri="RemotingService.rem"
                />
          </service>
          <channels>
              <channel ref="tcp" port="9100" useIpAddress="true"/>
          </channels>
        </application>
        <customErrors mode="off"/>
      </system.runtime.remoting>

    访问服务器地址: tcp://127.0.0.1:9100/RemotingService.rem  地址由两部分构成:IP端口 tcp://127.0.0.1:9100/  以及Uri:RemotingService.rem

    客户端测试代码:

     private void btnTest_Click(object sender, EventArgs e)
        {
          try
          {
            string sFunctionCallWebServiceUrl = string.Format("tcp://{0}{1}", txtIP.Text, txtService.Text + "/RemotingService.rem");
            MarshalByRefObject obj = (MarshalByRefObject)Activator.GetObject(typeof(MarshalByRefObject), sFunctionCallWebServiceUrl);
            object o = obj.GetLifetimeService();
            MessageBox.Show("测试成功");
          }
          catch (System.Net.Sockets.SocketException ex)
          {
            MessageBox.Show(ex.Message);
          }
          catch (Exception ex)
          {
            MessageBox.Show(ex.Message);
          }
        }

    由于MarshalByRefObject 是所有访问对象继承的基础,所以我想到用MarshalByRefObject来替代测试对象 实现测试效果。

    由于只是测试TCP端口服务是否可以连通 而不是测试服务的具体实现效果 所以这几行简单的代码就可以实现.

    
    
  • 相关阅读:
    【三】shiro入门 之 Realm
    【一】shiro入门 之 Shiro简介
    【二】shiro入门 之 身份验证
    [01] radio ,checkbox 表单文字对齐
    [02]时区时间获取
    【14】redux 之 redux-actions
    【02】webpack 之 入门
    【13】react 之 redux(2)
    【12】react 之 redux(1)
    【11】react 之 flux
  • 原文地址:https://www.cnblogs.com/Iyce/p/6186056.html
Copyright © 2011-2022 走看看