티스토리 뷰

Programming/Flex

Flex - SOAP 호출

파란크리스마스 2007. 8. 17. 03:50
728x90

출처

http://www.ibm.com/developerworks/webservices/library/ws-macroflex/
http://www.adobe.com/cfusion/communityengine/index.cfm?event=showdetails&postId=1821&productId=2
http://livedocs.adobe.com/labs/flex/3/html/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Book_Parts&file=data_access_048_3.html
http://flexdocs.kr/docs/flex2/langref/mx/rpc/soap/WebService.html
http://www.mail-archive.com/flexcoders@yahoogroups.com/msg64743.html

▶ SOAP


SOAP(Simple Object Access Protocol)에 대한 설명은 다른 사이트에 잘 나와 있으니 찾아 보세요.
여기에서는 Java로 SOAP 서버를 만들고, Tomcat으로 Web 서비스 하여, 클라이언트는 Delphi로 만들어 보겠습니다.
이와 같은 예가 외국 사이트를 찾아 보아도 별로 없더군요. 그래서 허접한 설명이지만 도움이 될까 해서 올립니다.
(기회가 되면 배열이나, Dataset도 구현 하고 싶지만 시간이 없어서...)

일부 소스와 내용은 에어콘 출판사의 차세대 자바 SOAP AXUS을 참조 했습니다.

▶ 준비물

JDK 1.4.x 이상 (http://java.sun.com)
Tomcat 4.1.36 (http://tomcat.apache.org/)
AXIS 1.4 (http://ws.apache.org/axis/)

▶ SOAP Web 서비스 설치

여기에서 JDK, Tomcat의 설치는 따로 하지 않겠습니다. 이것도 다른 사이트를 참조하세요.

1. axis-bin-1_4.zip 압축 풀기

Apache에서 받은 axis-bin-1_4.zip을 압축을 특정 폴더에 풀어 주세요. 저는 C:\SOAP\axis-1_4 에 풀었습니다.
앞으로 설명은 C:\SOAP\axis-1_4 으로 하겠습니다.

2. %tomcat_home%\conf\server.xml

아래 내용을 추가해서 AXIS 가상 경로를 추가 Tomcat을 다시 실행 시켜주세요.

<!-- Tomcat SOAP Context -->
<Context path="/axis" docBase="C:\SOAP\axis-1_4\webapps\axis" debug="0"
         reloadable="true" crossContext="true">
</Context>

▶ Java로 SOAP 서버 만들기

아래와 내용과 같이 HelloWorld.java을 만들고, 이 파일을 C:\SOAP\axis-1_4\webapps\axis 디렉토리에 확장자가 .jws로 수정 HelloWorld.jws을 C:\SOAP\axis-1_4\webapps\axis 복사해주세요.

HelloWorld.java 파일

public class HelloWorld {

  public HelloWorld() {
  }
 
  public String getHelloWorldMessage(String name) {
    return "Hello World to " + name;
  }
}

확인하기

지금까지 잘 하셨다면 브라우저에서 http://localhost:8080/axis/HelloWorld.jws 주소로 보시면 아래와 같이 나올 것입니다.

사용자 삽입 이미지














▶ Flex 에서 SOAP 호출하기

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
 <mx:Script>
  <![CDATA[
    import mx.rpc.soap.WebService;
    import mx.rpc.events.ResultEvent;
    import mx.rpc.events.FaultEvent;
    import mx.rpc.soap.LoadEvent;
   
    private function on_ButtonClick(event:Event):void {
      // WebService 객체 생성
      var webService:WebService = new WebService();
      webService.useProxy = false;
      // 응답결과를 받는 Event 메소드 등록
      webService.getHelloWorldMessage.addEventListener(ResultEvent.RESULT, resultListener);
      webService.getHelloWorldMessage.resultFormat = 'e4x';
      // SOAP 호출 실패 Event 메소드 등록
      webService.addEventListener(FaultEvent.FAULT, faultHandler);
//      webService.wsdl = "http://localhost:8080/axis/HelloWorld.jws?wsdl";
      // WSDL 로딩
      webService.loadWSDL("http://localhost:8080/axis/HelloWorld.jws?wsdl");
      // SOAP 호출
      webService.getHelloWorldMessage(Text1.text);
    }
   
    public function resultListener(event:ResultEvent):void {
      var xmlDoc:XML = new XML(event.result.getHelloWorldMessageReturn);
//      mx.controls.Alert.show(xmlDoc.text());
      Text2.text = xmlDoc.text();
    }
   
    public function faultHandler(event:FaultEvent):void {
      //deal with event.fault.faultString, etc
      mx.controls.Alert.show(event.fault.faultString);
    }       
   ]]>
  </mx:Script>

 <mx:Button x="178" y="13" label="Call SOAP" click="on_ButtonClick(event)" id="Button1" />
 <mx:TextArea x="10" y="10" id="Text1" fontSize="14" text="AXIS" height="25"/>
 <mx:TextArea x="56" y="43" id="Text2" height="21" width="204"/>
 <mx:Label x="10" y="44" text="Result :"/>
 
</mx:Application>

▶ 실행 결과

사용자 삽입 이미지

댓글
300x250
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함