Package axiom;
Import java. util. date;
Import org. Apache. Axiom. om. omw.actfactory;
Import org. Apache. Axiom. om. omelement;
Import org. Apache. Axiom. om. omfactory;
Import org. Apache. Axiom. om. omnamespace;
Import org. Apache. Axiom. Soap. soap11constants;
Import org. Apache. axis2.axisfault;
Import org. Apache. axis2.constants;
Import org. Apache. axis2.addressing. endpointreference;
Import org. Apache. axis2.client. options;
Import org. Apache. axis2.client. serviceclient;
Import org. Apache. axis2.transport. http. httpconstants;
Import org. Apache. axis2.transport. http. httptransportproperties. proxyproperties;
Public class weatheraxiomclient {
Private Static endpointreference targetepr =
New endpointreference (
Http://www.webxml.com.cn/WebServices/WeatherWebService.asmx ");
Private Static omfactory FAC = omdomainactfactory. getomfactory ();
Static omnamespace omns = FAC. createomnamespace ("http://WebXml.com.cn/", "TNS ");
Public static void main (string ARGs []) throws axisfault {
Date start = new date ();
System. Out. println ("START:" + start );
Serviceclient sender = new serviceclient ();
/***************************** City ********** ****************************/
// Sender. setoptions (buildoptions ("http://WebXml.com.cn/getSupportCity "));
// Omelement result = sender. sendreceive (buildparam ("getsupportcity", new string [] {"byprovincename"}, new string [] {"all "}));
// Query the information of domestic and foreign cities or regions supported by this weather forecast Web Services
/*************************************** ***********************************/
********** ****************************/
// Sender. setoptions (buildoptions ("http://WebXml.com.cn/getSupportProvince "));
// Omelement result = sender. sendreceive (null );
// Call the province method to obtain information about continents, provinces, and cities supported by the weather forecast Web Services.
/*************************************** ***********************************/
/**************************** Dataset ********** ****************************/
// Sender. setoptions (buildoptions ("http://WebXml.com.cn/getSupportDataSet "));
// Omelement result = sender. sendreceive (null );
// Obtain information about continents, provinces, and cities supported by the weather forecast Web Services
/*************************************** ***********************************/
/*************************** Weather ********** ****************************/
// Sender. setoptions (buildoptions ("http://WebXml.com.cn/getWeatherbyCityName "));
// Omelement result = sender. sendreceive (buildparam ("getweatherbycityname", new string [] {"thecityname"}, new string [] {"Hangzhou "}));
// Query the weather conditions, current weather conditions, weather and life indexes in the next three days based on the city or region name.
/*************************************** ***********************************/
Sender. setoptions (buildoptions ("http://WebXml.com.cn/getWeatherbyCityNamePro "));
Omelement result = sender. sendreceive (buildparam ("getweatherbycitynamepro", new string [] {"thecityname", "theuserid"}, new string [] {"Hangzhou", "01 "}));
System. Out. println (result );
Date end = new date ();
System. Out. println ("end:" + end );
System. Out. println ("between:" + (end. gettime ()-start. gettime ()));
}
/**
* @ See call WebService to obtain cities supported by weather forecasts
* @ Return
*/
Public static omelement buildparam (string method, string [] Arg, string [] Val ){
Omelement DATA = FAC. createomelement (method, omns );
For (INT I = 0; I <Arg. length; I ++ ){
Omelement inner = FAC. createomelement (ARG [I], omns );
Inner. settext (Val [I]);
Data. addchild (inner );
}
Return data;
}
/**
* @ See set Connection Properties
* @ Return
*/
Public static options buildoptions (string action ){
Options = new options ();
Options. setsoapversionuri (soap11constants. soap_envelope_namespace_uri );
Options. setaction ("http://WebXml.com.cn/getSupportCity ");
Options. setto (targetepr );
Options. settransportinprotocol (constants. transport_http );
Options. setproperty (httpconstants. Chunked, "false"); // The setting is unrestricted.
Options. setproperty (httpconstants. Proxy, buildproxy ());
Options. setproperty (constants. configuration. http_method, httpconstants. http_method_post );
// Options. setaction (action );
Return options;
}
/**
* @ See sets proxy Properties
* @ Return
*/
Public static proxyproperties buildproxy (){
Proxyproperties = new proxyproperties ();
Proxyproperties. setproxyname ("172.19.18.22 ");
Proxyproperties. setproxyport (8080 );
Return proxyproperties;
}
}
The problem lies in the fact that I have fixed a line of comment. You must set action. Otherwise, the server will not be able to process the request and you do not know which method you are referencing. Therefore, the server will report the instance where the object reference is not set to the object.