Andriod调用WebService交互(.net)

来源:互联网 发布:centos libudev.h 编辑:程序博客网 时间:2024/04/27 13:48

android端:

final static String NAME_SPACE = "http://tempuri.org/";

final static String SERVICE_URL = "http://192.168.0.174:8025/WebService1.asmx";
// 调用的方法
String methodName = "mysql ";
String soapAction = "http://tempuri.org/mysql";
private EditText txt1,name,job;
String on;
String wo;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txt1 = (EditText) findViewById(R.id.editText1);
name = (EditText) findViewById(R.id.name);
job = (EditText) findViewById(R.id.job);


}
public void onclick(View view){
on=name.getText().toString().trim();
wo= job.getText().toString().trim();
get();
}
String name_1;
private void get() {

new AsyncTask<Void, Void, Void>(){


@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
}
@Override
protected Void doInBackground(Void... params) {
// TODO Auto-generated method stub

// 使用soap1.1协议创建Envelop对象
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
// 实例化SoapObject对象
SoapObject request = new SoapObject(NAME_SPACE, methodName);
/**
* 设置参数,参数名不一定需要跟调用的服务器端的参数名相同,只需要对应的顺序相同即可
* */
request.addProperty("name", on);
request.addProperty("department", wo);
// 将SoapObject对象设置为SoapSerializationEnvelope对象的传出SOAP消息
envelope.dotNet=true;
envelope.bodyOut = request;
envelope.setOutputSoapObject(request);
new MarshalBase64().register(envelope);
// 创建httpTransportSE传输对象
HttpTransportSE ht = new HttpTransportSE(SERVICE_URL);
try {
// 调用webService
ht.call(soapAction, envelope);
if (envelope.getResponse() != null) {
SoapObject result = (SoapObject) envelope.bodyIn;
name_1 = result.getProperty(0).toString();
System.out.println("----------------------"+name);
//txt1.setText(name_1);
} else {

}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
            //数据显示
@Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
txt1.setText(name_1);
}


}.execute();

}

.net服务端:

  [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }
        [WebMethod(Description = "参数返回中文方法")]
        public string myhello(string name, string department)
        {
            return "您的姓名:" + name + "," + "您的单位:" + department;
        }

0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 干镀锌让环保查了怎么办 水管软管生锈了拧不动怎么办 镀锌管会生锈吗.怎么办 冷镀锌钢管生锈了怎么办 卖了过期的东西怎么办 喝到了假的饮料怎么办 烧汤总是溢锅怎么办 脚踩垃圾桶坏了怎么办 连衣裙特别容易起褶怎么办 施肥过度烧根了怎么办 农作物施用尿素发生肥害怎么办? 水稻尿素施多了怎么办 花施肥施多了怎么办 玉米被化肥烧了怎么办 撒施复合肥没有充分融化怎么办 绿箩化肥施多了怎么办 辣椒化肥施多了怎么办? 化肥施多了烧苗怎么办 绿植施肥施多了怎么办 盆栽肥料放多了怎么办 三环复合肥怎么办啊 母猪下崽后不吃食怎么办 猪自配料料槽不下怎么办 美甲边缘起翘怎么办 猪粪流到鱼塘里鱼死了怎么办啊 在基本农田建有机肥厂怎么办 有机肥厂的环评怎么办 织玻璃纤维网布环评怎么办 吃了受潮的奶粉怎么办 喝了受潮的奶粉怎么办 刚买的奶粉受潮怎么办 羊不小心吃了化肥怎么办 阿胶粉结成块了怎么办 半桶奶粉受潮了怎么办 眉粉受潮了结块怎么办 刚买的奶粉结块怎么办 袋装白糖成坨了怎么办 一袋子白糖硬了怎么办 粉饼上有一层油怎么办 葡萄后期氮肥施用过多怎么办 没洗的菜吃了怎么办