2011년 10월 20일 목요일

Axis Ant task을 이용한 WebService Client 개발


Step 1: 필요한 axis 라이브러리 설치

URL: http://axis.apache.org/axis/
  • axis-ant.jar
  • axis.jar
  • commons-discovery-0.2.jar
  • commons-logging-1.0.4.jar
  • jaxrpc.jar
  • log4j-1.2.8.jar
  • saaj.jar
  • wsdl4j-1.5.1.jar


Step 2: Ant 설치
ant 최신 버전을 설치 한다.

Step 3: Ant Build Script 작성
<project name="wsclient" default="build">
<property name="axis.home" value="./lib" />
<property name="src-gen.dir" value="./src" />
<property name="build.dir" value="./build"/>
<property name="wsdl" value="http://t320webservices.open.ac.uk/t320/services/Version?wsdl" />

<path id="axis.classpath">
<fileset dir="${axis.home}">
<include name="**/*.jar" />
</fileset>
</path>
<taskdef resource="axis-tasks.properties" classpathref="axis.classpath" />
<target name="init">
<mkdir dir="${build.dir}" />
<mkdir dir="${src-gen.dir}" />
<delete includeemptydirs="true" >
<fileset dir="${build.dir}" includes="**/*.*" />
</delete>
<delete includeemptydirs="true">
<fileset dir="${src-gen.dir}" includes="**/*.*" />
</delete>
</target>
<target name="clean">
<delete includeemptydirs="true">
<fileset dir="${build.dir}" includes="**/*.*" />
</delete>
<delete includeemptydirs="true">
<fileset dir="${src-gen.dir}" includes="**/*.*" />
</delete>
</target>
<target name="build" depends="compile">
<jar jarfile="${build.dir}/${ant.project.name}.jar">
      <fileset dir="${build.dir}"></fileset>
</jar>
</target>
<target name="gen" depends="init">
<axis-wsdl2java helpergen="false" output="${src-gen.dir}" testcase="false" verbose="true" url="http://t320webservices.open.ac.uk/t320/services/Version?wsdl"/>
<axis-wsdl2java helpergen="false" output="${src-gen.dir}" testcase="false" verbose="true" url="http://t320webservices.open.ac.uk/t320/services/Duty2PayService?wsdl"/>
</target>
<target name="compile" depends="gen">
<javac srcdir="${src-gen.dir}" destdir="${build.dir}" classpathref="axis.classpath" debug="on">
<src path="${src-gen.dir}" />
</javac>
</target>
</project>


Step 4: WS Client Code
package uc.ac.service;

import java.rmi.RemoteException;
import javax.xml.rpc.ServiceException;
import org.apache.axis.AxisFault;
import uk.ac.open.t320.GetAxisVersionResponse;
import uk.ac.open.t320.VersionLocator;
import uk.ac.open.t320.VersionPortType;

public class VersionServiceTest {

public static void main(String[] args) {
try {
String endPoint = "http://t320webservices.open.ac.uk/t320/services/Version?wsdl";
VersionLocator loca = new VersionLocator();
loca.setVersionSOAP11port_httpEndpointAddress(endPoint);
VersionPortType stub = loca.getVersionSOAP11port_http();
GetAxisVersionResponse rtn = stub.getAxisVersion();
System.out.println(rtn.get_return());
} catch (AxisFault e) {
e.printStackTrace();
} catch (RemoteException e) {
e.printStackTrace();
} catch (ServiceException e) {
e.printStackTrace();
}
}
}

Which Mobile App Development Option is Better?

Different alternatives to native code development have their own advantages and philosophy behind. No one tool or approach can be clearly ma...