Common services: http: //www.webxml.com.cn/zh_cn/support.aspx
Missing documents may be used ArrayOfString.java
Package com.test.wes.weather; Import of java.util.ArrayList; Import java.util.List; Import javax.xml.bind.annotation.XmlAccessType; Import javax.xml.bind.annotation.XmlAccessorType; Import the javax.xml. bind.annotation.XmlElement; Import javax.xml.bind.annotation.XmlType; / ** * <P> ArrayOfString Complex Java class type. * * <P> or less contained in the specified pattern segment in such a desired content. * * <Pre> * & lt; complexType name = "ArrayOfString"> * & lt; complexContent> * & lt; Restriction Base = "{ http://www.w3.org/2001/XMLSchema } anyType"> * <element name="string" type="{http://www.w3.org/2001/XMLSchema}string" maxOccurs="unbounded" minOccurs="0"/> * </sequence> * </restriction> * </complexContent> * </complexType> * </pre> * * */ @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "ArrayOfString", propOrder = { "string" }) public class ArrayOfString { @XmlElement(nillable = true) protected List<String> string; /** * Gets the value of the string property. * * <p> * This accessor method returns a reference to the live list, * not a snapshot. Therefore any modification you make to the * returned list will be present inside the JAXB object. * This is why there is not a <CODE>set</CODE> method for the string property. * * <p> * For example, to add a new item, do as follows: * <pre> * getString().add(newItem); * </pre> * * * <p> * Objects of the following type(s) are allowed in the list * {@link String } * * */ public List<String> getString() { if (string == null) { string = new ArrayList<String>(); } return this.string; } }
wsimport usage
Usage: the wsimport [options] < WSDL_URI > \ wherein [options] comprising: -b < path > Specifies jaxws / jaxb binding file or append mode (each < path > must have its own -b) -B < jaxbOption > pass this option to JAXB schema compiler -catalog < file > Specifies to resolve external entity references catalog file support TR9401, XCatalog and OASIS XML Catalog format. -d < Directory > specify the placement location of the output files generated -encoding < encoding > Specify the source file character encoding used -extension allow vendor extensions - not follow the standard specified functions. Extended use can cause the application not portable or can not interoperate with other implementations -help display help -httpproxy: < Host > : < Port > Specifies the HTTP proxy server (default port 8080) the -keep reservations generated files -p < PKG > targeting package -quiet wsimport hidden output -s < Directory > Specifies the location of the source file placement generated -target < Version > According to a given specification version JAXWS generated code defaults to 2.2, 2.0 is acceptable, 2.1 and 2.2 e.g., 2.0 JAXWS 2.0 specification will generate code that is compatible -verbose about what to do in the compiler's output message -version output version information -wsdllocation < LOCATION > @ WebServiceClient.wsdlLocation value -clientjar < jarfile > create Artifact generated jar file and needed to invoke a Web service WSDL metadata. -generateJWS JWS implementation file generation stub -implDestDir < Directory > Specifies the location of the generated JWS implementation file -implServiceName < name > Generating a local part of the service name JWS implementation -implPortName < name > generated port name of the local portion of JWS implementation \ extensions: -XadditionalHeaders mapping header is not bound to a request or response message is not bound to a Java method parameter -Xauthfile file for authorization information to the following format: HTTP: // username:? wsdl [email protected]/stock the -Xdebug output debugging information -Xno-addressing-databinding allow W3C EndpointReferenceType to Java binding -Xnocompile not compiled Java file -XdisableAuthenticator disable verification procedures used by the JAX-WS RI, ignored -Xauthfile option (if set) -XdisableSSLHostnameVerification disable SSL host name when extracting wsdl verification \ Example: wsimport the stock.wsdl -b stock.xml -b stock.xjb wsimport -d Generated http://example.org/stock?wsdl
The usual usage
wsimport -encoding utf-8 -p com.test.wes.weather -s . http://ws.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl
but
First download the file down WeatherWS.asmx
Then in WeatherWS.asmx
<s:element ref="s:schema"/><s:any/>全部替换为 <s:any minOccurs="2" maxOccurs="2"/>
wsimport -encoding utf-8 -p com.test.wes.weather -s . WeatherWS.asmx
Running the above sentence, the following code is generated
package com.test.wec; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.util.List; import javax.xml.namespace.QName; import javax.xml.ws.Service; import com.test.wes.phone.MobileCodeWSSoap; import com.test.wes.weather.ArrayOfString; import com.test.wes.weather.WeatherWS; import com.test.wes.weather.WeatherWSSoap; public class ServiceClient { public static void main(String[] args) throws IOException { //创建WSDL的URL,注意不是服务地址 // URL url = new URL("http://ws.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl"); // // //创建服务名称 // //1.namespaceURI - 命名空间地址 // //2.localPart - 服务视图名 // QName qname = new QName("http://WebXml.com.cn/", "qqOnlineWebService"); // // //创建服务视图 // //参数解释: // //1.wsdlDocumentLocation - wsdl地址 // //2.serviceName - 服务名称 // Service service = Service.create(url, qname); // //获取服务实现类 //// QqOnlineWebServiceSoap qqonlineSsSoap =service.getPort(QqOnlineWebServiceSoap.class); //// //调用查询方法 //// String result = qqonlineSsSoap.qqCheckOnline("1565465"); //// System.out.println(result); WeatherWS factory = new WeatherWS(); //根据工厂创建一个WeatherWSSoap对象 WeatherWSSoap weatherWSSoap = factory.getWeatherWSSoap(); //调用WebService提供的getWeather方法获取南宁市的天气预报情况 ArrayOfString weatherInfo = weatherWSSoap.getSupportCityString("广东"); List<String> lstWeatherInfo = weatherInfo.getString(); //遍历天气预报信息 for (String s : lstWeatherInfo) { System.out.print(s+"|"); } System.out.println(); ArrayOfString weatherInfo1 = weatherWSSoap.getWeather("广州", ""); List<String> lstWeatherInfo1 = weatherInfo1.getString(); //遍历天气预报信息 for (String s : lstWeatherInfo1) { System.out.print(s+"|"); } System.out.println(); } }