HaiQuanKing 2016-02-26 05:48 采纳率: 0%
浏览 1532

安卓端调用WebService传参,服务端接收不了数据

代码如下:
public class MainActivity extends Activity {
private static final String NAMESPACE="http://service.ams.com/";
private static final String URL="http://220.231.228.87:8080/InstallWebService/intallService";
private static final String METHOD_NAME="installDevice";
private SoapObject detail;
private TextView message;
private Handler handler;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    message=(TextView) findViewById(R.id.message);
    this.findViewById(R.id.button).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            new Thread(){
                public void run() {
                    installtion();
                };
            }.start();


        }
    });
    handler=new Handler(){
        public void handleMessage(Message msg) {
            message.setText("从webService获取的数据:"+(String)msg.obj);
        };
    };

}




protected void installtion() {
    SoapObject rpc = new SoapObject(NAMESPACE,METHOD_NAME); 
    String json="{"+"";
    json+="\"userId\""+":"+"\""+207+"\""+",";
    json+="\"loginId\""+":"+"\""+"AHAHAHAHAA"+"\""+",";
    json+="\"deviceId\""+":"+47397+",";
    json+="\"groupId\""+":"+559+",";
    json+="\"Time\""+":"+"\""+new SimpleDateFormat().format(new Date())+"\""+",";
    json+="\"brand\""+":"+"\"宝马\""+",";
    json+="\"model\""+":"+"\"R1\""+",";
    json+="\"color\""+":"+"\"黑\""+",";
    json+="\"carNum\""+":"+"\"粤B88888\""+",";
    json+="\"carName\""+":"+"\"宝马\""+",";
    json+="\"connectionType\""+":"+"1"+",";
    json+="\"oilPump\""+":"+"1"+",";
    json+="\"VDD\""+":"+"\"黑色\""+",";
    json+="\"GND\""+":"+"\"黑色\""+",";
    json+="\"deviceImgUrl\""+":"+"\"\""+",";
    json+="\"connectionIntallImgUrl\""+":"+"\"\""+",";
    json+="\"obligateUrl\""+":"+"\"\""+",";
    json+="\"InstallPosition\""+":"+"\"车头\""+",";
    json+="\"DBServer\""+":"+1+"}";
    JSONObject myjson = null;
    try {
        myjson=new JSONObject(json);
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }


    rpc.addProperty("arg0",myjson.toString()); 
     SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
     envelope.bodyOut = rpc;  
        // 设置是否调用的是dotNet开发的WebService  
        envelope.dotNet = true;  
        // 等价于envelope.bodyOut = rpc;  
        envelope.setOutputSoapObject(rpc);  

        HttpTransportSE transport = new HttpTransportSE(URL);  
        try {  
            // 调用WebService  
            transport.call(NAMESPACE+METHOD_NAME, envelope);  
        } catch (Exception e) {  
            e.printStackTrace();  
        }  

        // 获取返回的数据  
        SoapObject object = (SoapObject) envelope.bodyIn;  
        // 获取返回的结果  
        String result = object.getProperty(0).toString();
        Message msg=new Message();
        msg.obj=result;
        handler.sendMessage(msg);
}




@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}

}
调用成功了,不过传参传不了,哪位大神帮忙看下,谢谢了

  • 写回答

2条回答 默认 最新

  • oyljerry 2016-02-26 14:19
    关注

    先抓包分析看看数据包是在什么地方丢弃了。

    评论

报告相同问题?

悬赏问题

  • ¥15 用matlab 实现通信仿真
  • ¥15 按键修改电子时钟,C51单片机
  • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))
  • ¥20 5037端口被adb自己占了
  • ¥15 python:excel数据写入多个对应word文档
  • ¥60 全一数分解素因子和素数循环节位数
  • ¥15 ffmpeg如何安装到虚拟环境
  • ¥188 寻找能做王者评分提取的
  • ¥15 matlab用simulink求解一个二阶微分方程,要求截图
  • ¥30 乘子法解约束最优化问题的matlab代码文件,最好有matlab代码文件