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

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

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

    posts - 32, comments - 153, trackbacks - 0, articles - 0
      BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理
    昨天把Web服務(wù)架好了,那今天自然要想怎么來遠(yuǎn)程調(diào)用了.
    于是寫了如下代碼:
    /**
    ?*?org.zsu.zouang
    ?*?2006-11-29
    ?
    */

    package?org.zsu.zouang;

    import?java.net.MalformedURLException;
    import?java.net.URL;
    import?java.rmi.RemoteException;

    import?javax.xml.namespace.QName;
    import?javax.xml.rpc.ServiceException;

    import?org.apache.axis.client.Call;
    import?org.apache.axis.client.Service;

    /**
    ?*?2006-11-29
    ?*?
    @author?Zou?Ang
    ?*?Contact?<a?href?="mailto:richardeee@gmail.com">Zou?Ang</a>
    ?
    */

    public?class?MyBookServiceClient?{
    ????
    private?static?final?String?endPoint?=?"http://localhost:8080/axis/org/zsu/zouang/BookTitleService.jws?wsdl";
    ????
    public?static?void?main(String?args[]){
    ????????Service?service?
    =?new?Service();
    ????????
    try?{
    ????????????Call?call?
    =?(Call)service.createCall();
    ????????????call.setTargetEndpointAddress(
    new?URL(endPoint));
    ????????????call.setOperationName(
    new?QName("getBookTitle"));
    ????????????String?result?
    =?(String)call.invoke(new?Object[]{"0130895601"});
    ????????????System.out.println(result);
    ????????}
    ?catch?(ServiceException?e)?{
    ????????????
    //?TODO?Auto-generated?catch?block
    ????????????e.printStackTrace();
    ????????}
    ?catch?(MalformedURLException?e)?{
    ????????????
    //?TODO?Auto-generated?catch?block
    ????????????e.printStackTrace();
    ????????}
    catch(RemoteException?e){
    ????????????e.printStackTrace();
    ????????}

    ????}

    }

    控制臺輸出:
    -?Unable?to?find?required?classes?(javax.activation.DataHandler?and?javax.mail.internet.MimeMultipart).?Attachment?support?is?disabled.
    Advanced?Java?
    2?Platform?How?to?Program
    成功啦!
    在代碼中加上這一句:
    System.out.println(call.getResponseMessage().getSOAPPartAsString());
    會看到控制臺輸出:
    <?xml?version="1.0"?encoding="utf-8"?>
    <soapenv:Envelope?xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"?xmlns:xsd="http://www.w3.org/2001/XMLSchema"?xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

    ????
    <soapenv:Body>
    ????
    <getBookTitleResponse?soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
    ????????
    <getBookTitleReturn?xsi:type="xsd:string">
    ????????????Advanced?Java?2?Platform?How?to?Program
    ????????
    </getBookTitleReturn>
    ????
    </getBookTitleResponse>
    ????
    </soapenv:Body>
    </soapenv:Envelope>

    改進(jìn)了一下,使用Swing建立一個圖形化界面:
    /**
    ?*?2006-11-29
    ?*?
    @author?Zou?Ang
    ?*?Contact?<a?href?="mailto:richardeee@gmail.com">Zou?Ang</a>
    ?
    */

    public?class?MyBookClient?extends?JFrame?{

    ????
    private?final?static?int?FRAME_WIDTH?=?500;
    ????
    private?final?static?int?FRAME_HEIGHT?=?100;
    ????
    ????
    public?MyBookClient(String?title)?{
    ????????
    super(title);
    ????????getContentPane().setLayout(
    new?GridLayout(2?,?2));
    ????????
    final?String?endPoint?=?"http://localhost:8080/axis/org/zsu/zouang/BookTitleService.jws?wsdl";
    ????????
    final?JLabel?resultLabel?=?new?JLabel();
    ????????
    final?JComboBox?bookISDNBox?=?new?JComboBox();
    ????????bookISDNBox.addItem(
    "0130895601");
    ????????bookISDNBox.addItem(
    "0430895717");
    ????????bookISDNBox.addItem(
    "0430293636");
    ????????bookISDNBox.addItem(
    "0130923613");
    ????????
    ????????
    this.setSize(FRAME_WIDTH,?FRAME_HEIGHT);
    ????????JButton?serviceButton?
    =?new?JButton("Get?Book?Title");
    ????????serviceButton.addActionListener(
    new?ActionListener(){

    ????????????
    public?void?actionPerformed(ActionEvent?e)?{
    ????????????????
    //?TODO?Auto-generated?method?stub
    ????????????????try?{
    ????????????????????Service?service?
    =?new?Service();
    ????????????????????Call?call?
    =?(Call)service.createCall();
    ????????????????????call.setTargetEndpointAddress(
    new?URL(endPoint));
    ????????????????????call.setOperationName(
    new?QName("getBookTitle"));
    ????????????????????String?result?
    =?(String)call.invoke(bookISDNBox.getSelectedObjects());
    ????????????????????resultLabel.setText(result);
    ????????????????}
    ?catch?(AxisFault?e1)?{
    ????????????????????
    //?TODO?Auto-generated?catch?block
    ????????????????????e1.printStackTrace();
    ????????????????}
    ?catch?(MalformedURLException?e1)?{
    ????????????????????
    //?TODO?Auto-generated?catch?block
    ????????????????????e1.printStackTrace();
    ????????????????}
    ?catch?(RemoteException?e1)?{
    ????????????????????
    //?TODO?Auto-generated?catch?block
    ????????????????????e1.printStackTrace();
    ????????????????}
    ?catch?(ServiceException?e1)?{
    ????????????????????
    //?TODO?Auto-generated?catch?block
    ????????????????????e1.printStackTrace();
    ????????????????}

    ????????????}

    ????????}
    );
    ????????
    ????????getContentPane().add(
    new?JLabel("Please?ISDN?number"));
    ????????getContentPane().add(bookISDNBox);
    ????????getContentPane().add(resultLabel);
    ????????getContentPane().add(serviceButton);
    ????}

    ????
    ????
    public?static?void?main(String?args[]){
    ????????MyBookClient?client?
    =?new?MyBookClient("Book?Title?Service");
    ????????client.setDefaultCloseOperation(EXIT_ON_CLOSE);
    ????????client.setVisible(
    true);
    ????}

    }

    評論

    # re: Web Service學(xué)習(xí)日記-11月29日-建立客戶端訪問Web Service  回復(fù)  更多評論   

    2006-11-29 23:21 by zhenghx[匿名]
    今天在圖書館看到你那本書,去借時管理員跟我說那本書不能借 =_=!
    郁悶~~

    # re: Web Service學(xué)習(xí)日記-11月29日-建立客戶端訪問Web Service  回復(fù)  更多評論   

    2006-11-29 23:30 by Zou Ang
    什么叫那本書不能借?我都借著在看了

    # re: Web Service學(xué)習(xí)日記-11月29日-建立客戶端訪問Web Service  回復(fù)  更多評論   

    2006-11-30 23:53 by Tauruser
    哪本書?

    # re: Web Service學(xué)習(xí)日記-11月29日-建立客戶端訪問Web Service  回復(fù)  更多評論   

    2007-01-25 15:51 by 冷面閻羅
    那建一個罪簡單的Web Service ,應(yīng)該如何?
    主站蜘蛛池模板: 亚洲va久久久噜噜噜久久男同| 国产免费久久精品丫丫| 亚洲va无码手机在线电影| 国产女高清在线看免费观看| 一级毛片免费毛片一级毛片免费| 羞羞漫画登录页面免费| 亚洲av日韩av综合| 亚洲色图视频在线观看| 亚洲人成色7777在线观看| 免费国产在线观看不卡| 成年男女男精品免费视频网站 | 中文字幕免费不卡二区| 国产一区二区三区亚洲综合| 亚洲人成综合网站7777香蕉| 亚洲综合激情视频| 亚洲av无码乱码国产精品fc2| 亚洲国产婷婷香蕉久久久久久| 毛片免费全部播放一级| 亚洲一区在线免费观看| 久久国产精品萌白酱免费| 中文字幕无码免费久久9一区9 | 好爽…又高潮了免费毛片| 巨波霸乳在线永久免费视频| 免费人成毛片动漫在线播放| 国产免费伦精品一区二区三区| 日韩大片在线永久免费观看网站| 国产精品无码亚洲精品2021| 亚洲熟妇无码AV不卡在线播放| 国产精品亚洲片在线va| 亚洲av乱码一区二区三区香蕉| 久久国产亚洲精品无码| 亚洲色成人网一二三区| 亚洲国产精品美女| 亚洲一卡2卡4卡5卡6卡残暴在线| 亚洲最新在线视频| 亚洲国产中文在线视频| 亚洲中文字幕人成乱码| 最新亚洲春色Av无码专区| 亚洲国产精品无码久久九九大片 | 在线成人爽a毛片免费软件| 日本高清免费观看|