作为程序员需要做哪些事情。
						
								
								
						
				
				
						
								上面说了这么多,那么,做为程序员我们需要做哪些事情呢?我想以下事情是我们需要做的。我想下列事情是我们需要做的(我们举一个列子来说明问题):
						
				
				
						
								
										
												1.
												  
										
								
						
						
								定义接口(
								
										IPerson
								
								)
						
				
				
						
								package com.unimas.datacollection.webservices.training.api;
						
				
				
						
								/**
						
				
				
						
								
										
												 *
								
								这是一个描述人信息的接口,通过接口我们可以得到如下信息:名字,性别,身高,年龄。
						
				
				
						
								
										
												 */
								
						
				
				
						
								public interface IPerson {
						
				
				
						
								
										
												    public String getName();
								
						
				
				
						
								
										
												    public String getSex();
								
						
				
				
						
								
										
												    public String toString();
								
						
				
				
						
								
										
												    public int getAge();
								
						
				
				
						
								
										
												    public int getTall();
								
						
				
				
						
								}
						
				
				
						
								
										
										 
						
				
				
				
				
				
				
						
								package com.unimas.datacollection.webservices.training.api;
						
				
				
						
								public interface IWs {
						
				
				
						
								
										
												    public IPerson getPersonInfo(String name,int age,int tall,boolean sex);
								
						
				
				
						
								}
						
				
				
						
								
										
										 
						
				
				
				
				
				
				
						
								
										
												2.
												  
										
								
						
						
								服务端程序的实现(实现接口):
						
				
				
						
								package com.unimas.datacollection.webservices.training.server;
						
				
				
						
								import com.unimas.datacollection.webservices.training.api.IPerson;
						
				
				
						
								public class PersonImpl implements IPerson{
						
				
				
						
								
										
												    private String m_name = null;
								
						
				
				
						
								
										
												    private boolean m_sex = true;
								
						
				
				
						
								
										
												    private int m_age = 0;
								
						
				
				
						
								
										
												    private int m_tall = 0;
								
						
				
				
						
								
										
												    public String getName() {
								
						
				
				
						
								
										
												        return m_name;
								
						
				
				
						
								
										
												    }
								
						
				
				
						
								
										
												    public boolean getSex() {
								
						
				
				
						
								
										
												        return m_sex;
								
						
				
				
						
								
										
												    }
								
						
				
				
						
								
										
												    public int getAge() {
								
						
				
				
						
								
										
												        return m_age;
								
						
				
				
						
								
										
												    }
								
						
				
				
						
								
										
												    public int getTall() {
								
						
				
				
						
								
										
												 
												       return m_tall;
								
						
				
				
						
								
										
												    }
								
						
				
				
						
								
										
												    public void setSex(boolean isMan) {
								
						
				
				
						
								
										
												        m_sex = isMan;
								
						
				
				
						
								
										
												    }
								
						
				
				
						
								
										
												    public void setName(String name) {
								
						
				
				
						
								
										
												        m_name = name;
								
						
				
				
						
								
										
												    }
								
						
				
				
						
								
										
												    public void setAge(int age) {
								
						
				
				
						
								
										
												        m_age = age;
								
						
				
				
						
								
										
												    }
								
						
				
				
						
								
										
												    public void setTall(int tall) {
								
						
				
				
						
								
										
												        m_tall = tall;
								
						
				
				
						
								
										
												    }
								
						
				
				
						
								}
						
				
				
						
								
										
										 
						
				
				
				
				
				
				
						
								
										
										 
						
				
				
				
				
				
				
						
								
										
										 
						
				
				
				
				
				
				
						
								
										
										 
						
				
				
				
				
				
				
						
								
										
										 
						
				
				
				
				
				
				
						
								package com.unimas.datacollection.webservices.training.server;
						
				
				
						
								import com.unimas.datacollection.webservices.training.api.IWs;
						
				
				
						
								import com.unimas.datacollection.webservices.training.api.IPerson;
						
				
				
						
								public class WsPersonServer implements IWs{
						
				
				
						
								
										
												    public IPerson getPersonInfo(String name, int age, int tall, boolean sex) {
								
						
				
				
						
								
										
												        PersonImpl person = new PersonImpl();
								
						
				
				
						
								
										
												        person.setAge(age);
								
						
				
				
						
								
										
												        person.setName(name);
								
						
				
				
						
								
										
												        person.setSex(sex);
								
						
				
				
						
								
										
												        person.setTall(tall);
								
						
				
				
						
								
										
												        return person;  
								
						
				
				
						
								
										
												    }
								
						
				
				
						
								}
						
				
				
						
								
										
												3.
												  
										
								
						
						
								客户端程序:
						
				
				
						
								
										WsPersonClient
								
								类:
						
				
				
						
								package com.unimas.datacollection.webservices.training.client;
						
				
				
						
								import com.unimas.datacollection.webservices.training.api.IWs;
						
				
				
						
								import com.unimas.datacollection.webservices.training.api.IPerson;
						
				
				
						
								import com.unimas.datacollection.webservices.training.server.PersonImpl;
						
				
				
						
								import org.apache.axis.client.Call;
						
				
				
						
								import org.apache.axis.client.Service;
						
				
				
						
								import javax.xml.namespace.QName;
						
				
				
						
								import javax.xml.rpc.ParameterMode;
						
				
				
						
								public class WsPersonClient implements IWs{
						
				
				
						
								private static final String Str_EndPoint = 
						
				
				
						
								"http://localhost:8080/axis/services/WsPersonServer";
						
				
				
						
								
										
												    private static final String s_serviceName = "WsPersonServer";
								
						
				
				
						
								
										
												    public WsPersonClient() {
								
						
				
				
						
								
										
												    }
								
						
				
				
						
								
										
												    public IPerson getPersonInfo(String name, int age, int tall, boolean sex) {
								
						
				
				
						
								
										
												        Service service = new Service();
								
						
				
				
						
								
										
												        Call call = null;
								
						
				
				
						
								
										
												        IPerson person = null;
								
						
				
				
						
								
										
												        try {
								
						
				
				
						
								
										
												            call = (Call) service.createCall();
								
						
				
				
						
								
										
												            call.setTargetEndpointAddress( new java.net.URL(Str_EndPoint));
								
						
				
				
						
								
										
												            QName qname = new QName(s_serviceName, "getPersonInfo");
								
						
				
				
						
								
										
												            call.setOperationName(qname);
								
						
				
				
						
								
										
												            call.addParameter("name", qname, ParameterMode.IN);
								
						
				
				
						
								
										
												            call.addParameter("age", qname, ParameterMode.IN);
								
						
				
				
						
								
										
												     
												       call.addParameter("tall", qname, ParameterMode.IN);
								
						
				
				
						
								
										
												            call.addParameter("sex", qname, ParameterMode.IN);
								
						
				
				
						
								
										
												            call.setReturnClass(IPerson.class);
								
						
				
				
						
								
										
												            call.setReturnType(qname, IPerson.class);
								
						
				
				
						
								
										
										 
						
				
				
				
				
				
				
						
								
										
												            QName qn = new QName("urn:WsPersonServer", "Person");
								
						
				
				
						
								
										
												            call.registerTypeMapping(PersonImpl.class, qn,
								
						
				
				
						
								
										
												        new org.apache.axis.encoding.ser.BeanSerializerFactory (PersonImpl.class,qn),
								
						
				
				
						
								
										
												        new org.apache.axis.encoding.ser.BeanDeserializerFactory(PersonImpl.class,qn));
								
						
				
				
						
								person = (IPerson)call.invoke(new Object[]{name,
						
				
				
						
								new Integer(age),
						
				
				
						
								new Integer(tall),
						
				
				
						
								new Boolean(sex)});
						
				
				
						
								
										
												        } catch(Exception e) {
								
						
				
				
						
								
										
												            e.printStackTrace();
								
						
				
				
						
								
										
												        }
								
						
				
				
						
								
										
												        return person;
								
						
				
				
						
								
										
												    }
								
						
				
				
						
								} 
						
				
				
						
								测试类:
								
										TestClient
								
						
				
				
						
								package com.unimas.datacollection.webservices.training.client;
						
				
				
						
								
										
										 
						
				
				
				
				
				
				
						
								import com.unimas.datacollection.webservices.training.api.IPerson;
						
				
				
						
								import com.unimas.datacollection.webservices.training.Servcie;
						
				
				
						
								public class TestClient {
						
				
				
						
								public static void main(String[] args) {
						
				
				
						
								
										
												        Servcie.deploy("C:/dev_myself/webServices/training/src/resources/deploy.personService.wsdd");
								
						
				
				
						
								
										
												        WsPersonClient wsClient = new WsPersonClient();
								
						
				
				
						
								
										
												        IPerson person = wsClient.getPersonInfo("syc",24,170,true);
								
						
				
				
						
								
										
												        System.out.println("Your Name     is:"+person.getName());
								
						
				
				
						
								
										
												        System.out.println("Your Age      is:"+person.getAge());
								
						
				
				
						
								
										
												        System.out.println("Your Stature is:"+person.getTall());
								
						
				
				
						
								
										
												        boolean isMan = person.getSex();
								
						
				
				
						
								
										
												        if(isMan) {
								
						
				
				
						
								
										
												            System.out.println("You are a man!");
								
						
				
				
						
								
										
												        } else {
								
						
				
				
						
								
										
												            System.out.println("You are a women!");
								
						
				
				
						
								
										
												        }
								
						
				
				
						
								
										
												    }
								
						
				
				
						
								}
						
				
				
						
								
										Servcie
								
								类:
						
				
				
						
								public class Servcie {
						
				
				
						
								
										
												    public static void deploy(String deployFile) {
								
						
				
				
						
								
										
												        AdminClient.main(new String[]{deployFile});
								
						
				
				
						
								
										
												    }
								
						
				
				
						
								
										
												    public static void undeploy(String undeployFile) {
								
						
				
				
						
								
										
												        AdminClient.main(new String[]{undeployFile});
								
						
				
				
						
								
										
												    }
								
						
				
				
						
								}
						
				
				
						
								
										
												4.
												  
										
								
						
						
								部署:编写
								
										deploy.personService.wsdd
								
								文件。内容如下:
						
				
				
						
								<deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
						
				
				
						
								
										
												    <service name="WsPersonServer" provider="java:RPC">
								
						
				
				
						
								
										
												        <parameter name="allowedMethods" value="*"/>
								
						
				
				
						
								
										
												        <parameter name="className" value="com.unimas.datacollection.webservices.training.server.WsPersonServer"/>
								
						
				
				
						
								
										
												        <beanMapping qname="myNS:Person" xmlns:myNS="urn:WsPersonServer" languageSpecificType="java:com.unimas.datacollection.webservices.training.server.PersonImpl"/>
								
						
				
				
						
								
										
												    </service>
								
						
				
				
						
								</deployment>
						
				
				
						
								并把它存放到某一个目录。
						
				
				
						
								
										
												5.
												  
										
								
						
						
								将些文件生成一个
								
										JAR
								
								包。然后把这个
								
										JAR
								
								包放到
								
										LIB
								
								目录下。启动
								
										TOMCAT
								
								。
						
				
				
						
								
										
												6.
												  
										
								
						
						
								先用
								
										IE
								
								访问服务,看服务是否已经启动:
						
				
				
						
								
										http://localhost:8080/axis/services/WsPersonServer
								
						
						
								。如果没有异常,那么就表示部署成功了。
						
				
				
						
								
										
												7.
												  
										
								
						
						
								启动测试程序测试客户端。
						
				
				
						
								注意:或许你现在很是迷惑,为什么不需要去修改
								
										Server-config.wsdd
								
								文件了。其实,这里我们已经修改了这个文件,已经把我们需要的服务部署到这个文件中了。就是下面语句代替了我们手工的工作:
						
				
				
						
								Servcie.deploy("C:/dev_myself/webServices/training/src/resources/deploy.personService.wsdd");
						
				
				
						程序开发中需要注意的问题。
						
								
								
						
				
				
						
								在使用
								
										AXIS
								
								开发
								
										WEB
								
								服务的时候,会遇到很多问题。比如:
								
										
												XML
										
								
								
										解析器出现的异常、
								
								发布
								
										Web
								
								服务时报告
								
										"Exception:: (404)Not Found"
								
								、客户端程序找不到可用的
								
										Web
								
								服务、
						
						序列化
						
								/
						
						反序列化等。当然,在开发中还会有更多的问题出现,下面这个网址介绍了对问题的情况描述和问题的解答。
						
								
								
						
				
				
				
				
						
								
										http://www-900.ibm.com/developerWorks/cn/webservices/ws-axisfaq/index.shtml
								
						
				
				
						关于序列化和反序列化的问题,可以参阅:
						
								
								
						
				
				
				
				
						
								
										http://it.icxo.com/htmlnews/2004/09/29/386559.htm
								
						
						
								。
						
				
				
						
								
										
										 
						
				
				
				
				
				
				
						目前还没有解决的问题。
						
								
								
						
				
				
						
								
										
												1.
												  
										
								
						
						
								在
								
										WEBSERVICE
								
								之间好象不能传递父类的信息:不管是合成的还是继承的。
						
				
				现在公司开发使用的序列化好象都是
				AXIS
				自带的序列化和反序列化。不过,写这个序列化和反序列化程序是比较困难的。