簡體   English   中英

代碼簽名和編寫步驟 public static void main(String args[] )

[英]Code signature and steps to write public static void main(String args[] )

使用WSDL2Java成功生成客戶端代碼的“WeatherService”WSDL。

在java文件和方法中應該寫入主class來訪問和執行進程?

  • WeatherServiceCallbackHandler.java

  • WeatherServiceStub.java

我認為應該遵循一些標准的簽名代碼步驟並訪問 WSDL 中可用的方法。

兩者都沒有。 您根本不應該觸摸生成的代碼。 您 class 應該調用生成的代碼以便與 Web 服務交互。

通常你會實例化一個服務定位器並使用它來獲得一個存根實現。 然后,您可以直接使用存根。

所以簡而言之,你的主要方法應該完全在一個單獨的 class 內。

請參閱下面的代碼,了解如何使用 wsdl2java 生成的存根實現:

package com.axis.weather;

import static com.axis.weather.WeatherServiceStub.*;

public class Main {
    public static void main(String[] args) {
        Weather w = new Weather();
        w.setHowMuchRain(2.2f);

        SetWeather wrapper = new SetWeather();
        wrapper.setArgs0(w);

        try {
            WeatherServiceStub stub = new WeatherServiceStub(); // will use http://localhost:8080/axis2/services/WeatherService.WeatherServiceHttpSoap12Endpoint/
            stub.setWeather(wrapper);
        } catch (java.rmi.RemoteException re) {
            re.printStackTrace();
        }
    }
}

問候
優素福

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM