zoukankan      html  css  js  c++  java
  • SOAP及Web Services

    我们可以通过SOAP服务器来访问预先定义好的对象,通过soap/rpc/driver就可做到,这也可以看作是同其他语言交互的一种很好的方式,服务器端存为server.rb


    require 'soap/rpc/standaloneServer'

    class InterestCalculator
      attr_reader :call_count
      def initialize
        @call_count=0
      end
      def compound(printcipal,rate,freq,years)
        @call_count+=1
        printcipal*(1.0+rate/freq)**(freq*years)
      end
    end

    NS='http://pragprog.com/InterestCalc'
    class Server2<SOAP::RPC::StandaloneServer
      def on_init
        calc=InterestCalculator.new
        add_method(calc,'compound','printcipal','rate','freq','years')
        add_method(calc,'call_count')
      end
    end
    svr=Server2.new('Calc',NS,'0.0.0.0',12321)
    trap('INT'){svr.shutdown}
    svr.start


    客户端代码存为client.rb
    require 'soap/rpc/driver'
    proxy=SOAP::RPC::Driver.new("http://localhost:12321","http://pragprog.com/InterestCalc")
    proxy.add_method('compound','principle','rate','freq','years')
    proxy.add_method('call_count')
    puts "Call count: #{proxy.call_count}"
    puts "5 years,compound annually: #{proxy.compound(100,0.06,1,5)}"
    puts "5 years,compound monthly: #{proxy.compound(100,0.06,12,5)}"
    puts "Call count: #{proxy.call_count}"

    我们在服务器端输入

    % ruby server.rb

    以打开服务器

    客户端中输入

    %ruby client.rb

    会显示

    Call count:0

    5 years,compound annually:133.8225776

    .......





  • 相关阅读:
    给最小化托盘增加右键菜单
    (转)c#实现开机自启动
    Socket代码
    (转)C# Socket简单例子(服务器与客户端通信)
    (转)C# Socket异步通信
    (转)winform pictureBox后台显示图片
    验证DataGridView单元格的值
    批处理判断是否有.net环境
    Winform判断是否已启动
    linux 下 apache启动、停止、重启命令
  • 原文地址:https://www.cnblogs.com/djcsch2001/p/2035861.html
Copyright © 2011-2022 走看看