简体   繁体   English

带有WCF Rest Service的通讯Android应用

[英]Comunication Android App with WCF Rest Service

I'm trying to communicate my Android App with a WCF REST service, but when I run the android app, always appears a message saying, unfortunately, android app has stopped. 我正在尝试将我的Android应用程序与WCF REST服务进行通信,但是当我运行android应用程序时,总是会出现一条消息,说不幸的是,android应用程序已停止。

Below is my call to the service , my app has one only activity that has a Button when a click executes the event LogarOnserver, as you can see below. 以下是我对服务的调用,当单击执行事件LogarOnserver时,我的应用程序只有一个活动,该活动具有一个Button,如下所示。 After the service return the response I take it and put in a TextView (_myPassWord). 服务返回响应后,我将其放入TextView(_myPassWord)中。

package com.arduino.ligthautomation;

import java.io.IOException;

import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;


import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;


 public class RegisterActivity extends Activity  {

EditText _myPassWord ;
EditText _myLogin;
private static final String URL_STRING =      "http://192.168.0.3:8080/lightautomationservice/1";

@Override

public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);

    //mostrando tela de login
    setContentView(R.layout.login);

     _myPassWord = (EditText)  findViewById(R.id.editTextPassword);
     _myLogin = (EditText)  findViewById(R.id.editTextUsuario);




}

public void logarOnServer (View v) throws IOException
{
    try{

         HttpClient httpclient = new DefaultHttpClient();
         HttpGet request = new HttpGet("http://192.168.0.3:8080/lightautomationservice/1");
         ResponseHandler<String> handler = new BasicResponseHandler();
         //you result will be String :
         String result = httpclient.execute(request, handler);

         _myLogin.setText(result);

           } catch (ClientProtocolException e) {
           // TODO Auto-generated catch block
            e.printStackTrace();
           } catch (IOException e) {
            // TODO Auto-generated catch block
             e.printStackTrace();
           }
}

}

Just a wild guess: you're doing a network request on the main(UI) thread. 只是一个疯狂的猜测:您正在对main(UI)线程进行网络请求。 A big no no. 大不对

Look up AsyncTask 查找AsyncTask

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 android-wcf其余服务通信 - android - wcf rest service communication Android应用程序与本机桌面应用程序的通信 - Android app and native desktop app comunication 从Android将图像发布到WCF Rest服务 - Posting image to wcf rest service from android 正在运行的 android 服务与同一服务内的 recyclerview 适配器之间的通信 - Comunication between a running android service and a recyclerview adapter inside the same service 服务器,JavaFX桌面应用程序和android应用程序之间的通信 - comunication between server, JavaFX desktop app and android app 将图像文件从Android发送到WCF REST服务 - Sending Image Files from Android to WCF REST Service Android应用程序请求WCF服务(SerializationException - utf-8相关) - Android app requests WCF service (SerializationException - utf-8 related) 连接到 WCF 服务的 Android 应用程序的身份验证(本地环境) - Authentication for Android app connecting to a WCF service (on-prem environment) 活动和服务之间的EventBus通信 - EventBus comunication between activity and service android应用程序和spring rest服务之间的httpost的字符编码问题 - Character encoding issue for httpost between android app and spring rest service
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM