Android调用Asp.Net平台开发的WebService

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
private Button btnLogin;
private EditText txtUserName;
private EditText txtuserPwd;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
   txtUserName = (EditText) findViewById(R.id.txtUserName); 
    txtuserPwd = (EditText) findViewById(R.id.txtUserPwd);
      btnLogin = (Button) findViewById(R.id.btnLogin);
      txtUserName.requestFocus();
      txtUserName.setCursorVisible(true);
      btnLogin.setOnClickListener(new OnClickListener(){         
  @Override
  public void onClick(View v) {
  // TODO Auto-generated method stub<br>      //发布后的WebService路径<br>      String url = "http://117.34.91.166:8017/WebServices/Userlogin.asmx";
    //命名空间<br>      String nameSpace = "http://tempuri.org/";
    //命名空间下的方法名<br>      String SOAP_ACTION  = "http://tempuri.org/GetUserLoginInfo";
    //方法名称<br>      String method = "GetUserLoginInfo";
    String userName=txtUserName.getText().toString();
    String userPwd=txtuserPwd.getText().toString();                           
    SoapObject request = new SoapObject(nameSpace, method);  <br>      //传递参数(注意:username和pwd必须和WebService方法里的参数名一样否则参数传递不过去)
    request.addProperty("username",userName);
    request.addProperty("pwd",userPwd);
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);       
    envelope.bodyOut = request;
    (new MarshalBase64()).register(envelope); <br>      // 最好使用ksoap2-android-assembly-2.3-jar-with-dependencies版本
    AndroidHttpTransport transport=new AndroidHttpTransport(url);
    envelope.dotNet = true;         
  try {
  transport.call(SOAP_ACTION, envelope);
  if(envelope.getResponse()!=null)
  {
  Object object = envelope.getResponse();                         
  String str = object.toString();
  if(str.equals("true"))
  {   
    //跳转页面<br>    Intent intent = new Intent();
  intent.setClass(MainActivity.this, LogManagerActivity.class);
  startActivity(intent);                 
  }
  else
      {       <br>        //弹出提示框             
   ShowDialog("登录失败!");
  }
  }
  }
  catch (Exception e)
  {
   e.printStackTrace();
  }               
    }});
  }
 
 private void ShowDialog(String message)
  {
      AlertDialog.Builder builder=new  AlertDialog.Builder(this);   
      builder.setTitle("提示");
      builder.setMessage(message);
      builder.setPositiveButton("确定", null);
      builder.create().show();
  }

  

Android调用Asp.Net平台开发的WebService,,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。