冯修远 2015-11-28 02:53 采纳率: 0%
浏览 1468

android调用webservice的传至问题

webservice端(地址:http://qingfeng-bbs.oicp.net:61/TCLYWebService.asmx)

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);
    }
}

}


android端传参数调用

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();
        }
    });
}

  • 写回答

2条回答 默认 最新

  • qq_21596089 2015-11-28 03:06
    关注

    dfdgnhfgnf

    评论

报告相同问题?

悬赏问题

  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致