WebService号码归属地查询

package com.example.mobile;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;

public class MainActivity extends Activity {
	private final String SERVICE_NS = "http://WebXml.com.cn/";
	private final String SERVICE_URL = "http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx";
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		new Thread(){
			public void run(){
				SoapObject obj = getMobileInfo("1587652****");
				Log.i("msg", obj.getPropertyAsString(0));
			}
		}.start();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	
	private SoapObject getMobileInfo(String mobile){
	
		String methodName = "getMobileCodeInfo";

        // 创建HttpTransportSE传输对象   
        HttpTransportSE httpTranstation = new HttpTransportSE(SERVICE_URL);
        
        httpTranstation.debug = true;  
        // 使用SOAP1.1协议创建Envelop对象   
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);  
        // 实例化SoapObject对象   
        SoapObject soapObject = new SoapObject(SERVICE_NS, methodName); 
        soapObject.addProperty("mobileCode", mobile);

       
        envelope.bodyOut = soapObject;  
        // 设置与.Net提供的Web Service保持较好的兼容性   
        envelope.dotNet = true;  
        try{  
            // 调用Web Service   
            httpTranstation.call(SERVICE_NS + methodName, envelope);  
            if (envelope.getResponse() != null){  
                // 获取服务器响应返回的SOAP消息   
                SoapObject result = (SoapObject) envelope.bodyIn;  
                return result;
            }  
        }catch (Exception e){  
            e.printStackTrace();  
        }
		
		return null;
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值