using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Services;
using TCLYWebService.Bean;
using TCLYWebService.DB;
using System.Web.Services.Protocols;
namespace TCLYWebService
{
///
/// TCLYWebService 的摘要说明
///
[WebService(Namespace = "http://qingfeng-bbs.oicp.net:61/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class TCLYWebService : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
[WebMethod]
public string InsertJd(string guojia, string shengji, string shiji, string xianji, string jdindex, string jdName, string locationX, string locationY)
{
DB.DB d = new DB.DB();
//JD jd = new JD();
//jd.Guojia = guojia;
//jd.Shengji = shengji;
//jd.Shiji = shiji;
//jd.Xianji = xianji;
//jd.Jdindex = jdindex;
//jd.JdName = jdName;
//jd.LocationX = Double.Parse(locationX);
//jd.LocationY = Double.Parse(locationY);
//string sql = string.Format("insert jd values('{0}','{1}','{2}','{3}','{4}','{5}',{6},{7})", jd.Guojia, jd.Shengji, jd.Shiji, jd.Xianji, jd.Jdindex, jd.JdName, jd.LocationX, jd.LocationY);
string sql = string.Format("insert jd values('{0}','{1}','{2}','{3}','{4}','{5}',{6},{7})", guojia, shengji, shiji, xianji, jdindex, jdName, locationX, locationY);
return d.inupdelData(sql);
}
}
}
private void initBtnListener() {
// TODO Auto-generated method stub
btninsertjd.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
// 执行webservice后返回的结果
final Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
if (msg.what == msg_suc) {
SoapObject result = (SoapObject) msg.obj;
// JSONObject obj=new
// JSONObject(result.getProperty(0).toString());
new AlertDialog.Builder(MainActivity.this).setTitle("提示")
.setMessage(result.getProperty(0).toString()).setPositiveButton("OK", null).show();
}
}
};
// 执行webService
new Thread(new Runnable() {
public void run() {
// 命名空间
String nameSpace = "http://qingfeng-bbs.oicp.net:61";
// 调用的方法名称
// String methodName = "InsertJd";
String methodName = "HelloWord";
// EndPoint
String endPoint = "http://qingfeng-bbs.oicp.net:61/TCLYWebService.asmx";
// SOAP Action
// String soapAction = "http://qingfeng-bbs.oicp.net:61/InsertJd";
String soapAction = "http://qingfeng-bbs.oicp.net:61/HelloWord";
// 实例化SoapObject对象
SoapObject soapObject = new SoapObject(nameSpace, methodName);
// soapObject.addAttribute("guojia", "中国");
// soapObject.addAttribute("shengji", "云南");
// soapObject.addAttribute("shiji", "保山");
// soapObject.addAttribute("xianji", "腾冲");
// soapObject.addAttribute("jdindex", "银杏村");
// soapObject.addAttribute("jdName", "银杏");
// soapObject.addAttribute("locationX", "45.12331");
// soapObject.addAttribute("locationY", "564.122313");
// soapObject.addProperty("guojia", "中国");
// soapObject.addProperty("shengji", "云南");
// soapObject.addProperty("shiji", "保山");
// soapObject.addProperty("xianji", "腾冲");
// soapObject.addProperty("jdindex", "银杏村");
// soapObject.addProperty("jdName", "银杏");
// soapObject.addProperty("locationX", "45.12331");
// soapObject.addProperty("locationY", "564.122313");
// JSONObject req = new JSONObject();
// try {
// req.accumulate("guojia", "中国");
// req.accumulate("shengji", "云南");
// req.accumulate("shiji", "保山");
// req.accumulate("xianji", "腾冲");
// req.accumulate("jdindex", "银杏");
// req.accumulate("jdName", "银杏村");
// req.accumulate("locationX", "45.12331");
// req.accumulate("locationY", "564.122313");
// } catch (JSONException e1) {
// // TODO Auto-generated catch block
// e1.printStackTrace();
// }
// soapObject.addProperty("parameters", req.toString());
// 使用soap1.1协议创建Envelop对象
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
envelope.bodyOut = soapObject;
envelope.dotNet = true;
// 等价于envelope.bodyOut = soapObject;
// envelope.setOutputSoapObject(soapObject);
HttpTransportSE ht = new HttpTransportSE(endPoint);
try {
ht.call(soapAction, envelope);
if (envelope.getResponse() != null) {
// 获取服务器响应返回的soap消息
SoapObject result = (SoapObject) envelope.bodyIn;
Message msg = new Message();
msg.obj = result;
msg.what = msg_suc;
handler.sendMessage(msg);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
// new AlertDialog.Builder(MainActivity.this)
// .setTitle("提示")
// .setMessage("执行了")
// .setPositiveButton("OK", null)
// .show();
}
});
}
dfdgnhfgnf
dfdgnhfgnf