2007년 5월 2일 수요일

[SOAP] 간단한 Server / Client 예제 작성 중

URL: http://guide.soaplite.com/#item_uri

Web Service에 대한 대략적 study와 병행해서 실제 perl의 SOAP::Lite를 사용하여  Web Service를 작성해 보고자 한다.

#============================
# business module
# date: 2007.5.2
#
package Demo;

  sub hi {
        my ($class, $a) = @_;

        return "HI $a \n";
  }

  sub bye {
    return "goodbye, cruel world";
  }

  #===============================
  # object Acess
  #
  sub new {
      my $self = shift;
      my $class = ref($self) || $self;
      bless {_temperature => shift} => $class;
  }
  sub as_fahrenheit {
      return shift->{_temperature};
  }
  sub as_celsius {
      return 5/9*(shift->{_temperature}-32);
  }
1;

#================================
# service.cgi
# date: 2007.5.2
#!/usr/bin/perl -w

  use SOAP::Transport::HTTP;
  use Demo;

  SOAP::Transport::HTTP::CGI
    -> dispatch_to('Demo')
    -> handle;


#================================
# client.pl
# date: 2007.5.2
#!perl -w
  use SOAP::Lite;
    # -> uri('http://www.ezadmin.co.kr')
  # uri는 class의 위치?
  print SOAP::Lite
    -> uri('http://[domain]/Demo')
    -> proxy('http://[domain]/service.cgi')
    -> hi( "123" )
    -> result;


결과
$ perl client.pl
HI 123

쩝 이 단순한 결과를 얻기 위해 하루종일 이렇게 저렇게 해보다니..ㅠ.ㅠ 내일은 autodispatch 에 대해서 작업할 예정

댓글 없음:

댓글 쓰기