SoapObject request =new SoapObject(http://service,"getName");
Request.addProperty("param1","value");
Request.addProperty("param2","value");
SoapSerializationEnvelope envelope=new SoapSerializationEnvelope(SoapEnvelope.VER11); Envelope.bodyOut = request;
HttpTransportSE ht=new HttpTransportSE("http://192.168.18.17:80
/axis2/service/SearchNewsService?wsdl");
ht.call(null,envelope);
SoapObject soapObject =( SoapObject) envelope.getResponse();
public class WebService extends Activity {
private static final String NAMESPACE = "http://WebXml.com.cn/";
// WebService地址
private static String URL = "http://www.webxml.com.cn/
webservices/weatherwebservice.asmx";
private static final String METHOD_NAME = "getWeatherbyCityName";
private static String SOAP_ACTION = "http://WebXml.com.cn/
getWeatherbyCityName";
private String weatherToday;
private Button okButton;
private SoapObject detail;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
okButton = (Button) findViewById(R.id.ok);
okButton.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
showWeather();
}
});
}
private void showWeather() {
String city = "武汉";
getWeather(city);
}
@SuppressWarnings("deprecation")
public void getWeather(String cityName) {
try {
System.out.println("rpc------");
SoapObject rpc = new SoapObject(NAMESPACE, METHOD_NAME);
System.out.println("rpc" + rpc);
System.out.println("cityName is " + cityName);
rpc.addProperty("theCityName", cityName);
AndroidHttpTransport ht = new AndroidHttpTransport(URL);
ht.debug = true;
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.bodyOut = rpc;
envelope.dotNet = true;
envelope.setOutputSoapObject(rpc);
ht.call(SOAP_ACTION, envelope);
SoapObject result = (SoapObject) envelope.bodyIn;
detail = (SoapObject) result
.getProperty("getWeatherbyCityNameResult");
System.out.println("result" + result);
System.out.println("detail" + detail);
Toast.makeText(WebService.this, detail.toString(),
Toast.LENGTH_LONG).show();
parseWeather(detail);
return;
} catch (Exception e) {
e.printStackTrace();
}
}
private void parseWeather(SoapObject detail)
throws UnsupportedEncodingException {
String date = detail.getProperty(6).toString();
weatherToday = "今天:" + date.split(" ")[0];
weatherToday = weatherToday + "\n天气:" + date.split(" ")[1];
weatherToday = weatherToday + "\n气温:"
+ detail.getProperty(5).toString();
weatherToday = weatherToday + "\n风力:"
+ detail.getProperty(7).toString() + "\n";
System.out.println("weatherToday is " + weatherToday);
Toast.makeText(WebService.this, weatherToday,
Toast.LENGTH_LONG).show();
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有