<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆 - 9, 文章 - 1, 評論 - 2, 引用 - 0
    數據加載中……

    跟我學WEBSERVICE(三)

    作為程序員需要做哪些事情。

    上面說了這么多,那么,做為程序員我們需要做哪些事情呢?我想以下事情是我們需要做的。我想下列事情是我們需要做的(我們舉一個列子來說明問題):

    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 自帶的序列化和反序列化。不過,寫這個序列化和反序列化程序是比較困難的。

    posted on 2007-03-24 16:03 趙貴陽 閱讀(590) 評論(0)  編輯  收藏 所屬分類: WEBSERVICE

    主站蜘蛛池模板: 国产黄色免费观看| 久久免费99精品国产自在现线 | 久久综合给合久久国产免费| 蜜桃成人无码区免费视频网站| 亚洲中文字幕日产乱码高清app| 亚洲国产精品一区| 精品久久久久久亚洲精品| 蜜芽亚洲av无码一区二区三区| j8又粗又长又硬又爽免费视频| 亚洲日本韩国在线| 亚洲国产美女在线观看 | 亚洲精品tv久久久久久久久| 亚洲综合一区二区| 污视频网站免费在线观看| 无码国产精品一区二区免费16| 天天天欲色欲色WWW免费| 久久精品国产精品亚洲| 亚洲自偷自偷在线成人网站传媒| 一级黄色片免费观看| 成人a视频片在线观看免费| 在线亚洲午夜片AV大片| 全部免费毛片在线播放| 亚洲制服在线观看| 国产白丝无码免费视频| 亚洲av再在线观看| 亚洲13又紧又嫩又水多| 啦啦啦www免费视频| 一级人做人a爰免费视频| 亚洲bt加勒比一区二区| 国产一级高青免费| 免费人成网站7777视频| 亚洲一区精品视频在线| 免费看男女下面日出水视频| 亚洲午夜电影在线观看高清| 日本一道高清不卡免费| 中文字幕在线观看亚洲日韩| 精品国产亚洲男女在线线电影 | 亚洲国产精品不卡在线电影| 四虎永久在线观看免费网站网址| 亚洲乱码国产一区三区| 亚洲精品在线免费观看|