<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 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理
    昨天把Web服務架好了,那今天自然要想怎么來遠程調用了.
    于是寫了如下代碼:
    /**
    ?*?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>

    改進了一下,使用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學習日記-11月29日-建立客戶端訪問Web Service  回復  更多評論   

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

    # re: Web Service學習日記-11月29日-建立客戶端訪問Web Service  回復  更多評論   

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

    # re: Web Service學習日記-11月29日-建立客戶端訪問Web Service  回復  更多評論   

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

    # re: Web Service學習日記-11月29日-建立客戶端訪問Web Service  回復  更多評論   

    2007-01-25 15:51 by 冷面閻羅
    那建一個罪簡單的Web Service ,應該如何?
    主站蜘蛛池模板: 国产日韩精品无码区免费专区国产 | 中文字幕在线亚洲精品| 亚洲精品无码高潮喷水A片软| 最近新韩国日本免费观看| 久久亚洲国产欧洲精品一| a级毛片免费播放| 亚洲精品无码永久中文字幕| 13小箩利洗澡无码视频网站免费 | 精品免费国产一区二区| 亚洲人成网站18禁止| 日本一道一区二区免费看| 春暖花开亚洲性无区一区二区| 国产成人精品123区免费视频| 香蕉97碰碰视频免费| 亚洲自偷自偷偷色无码中文| 精品国产污污免费网站 | 亚洲精品色播一区二区| 国产免费私拍一区二区三区| 乱淫片免费影院观看| 亚洲色婷婷六月亚洲婷婷6月| 一级毛片全部免费播放| 亚洲国产成人精品电影| 成年性生交大片免费看| 四虎精品成人免费视频| 久热综合在线亚洲精品| 日本阿v免费费视频完整版| 亚洲第一综合天堂另类专 | 免免费国产AAAAA片| 小说区亚洲自拍另类| 亚洲精品国产美女久久久| 免费在线视频你懂的| 亚洲AV成人一区二区三区观看| 亚洲美女高清一区二区三区| 91麻豆国产免费观看| 亚洲变态另类一区二区三区| 亚洲精品高清无码视频| 免费av欧美国产在钱| A片在线免费观看| 亚洲日韩精品无码专区加勒比| 国产成人综合亚洲亚洲国产第一页 | 免费一级毛片免费播放|