首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在Android中使用WCF服务

如何在Android中使用WCF服务
EN

Stack Overflow用户
提问于 2009-03-21 18:48:27
回答 5查看 103K关注 0票数 79

我正在用.NET创建一个服务器和一个用于安卓的客户端应用程序。我想实现一个身份验证方法,它将用户名和密码发送到服务器,服务器发送回一个会话字符串。

我不熟悉WCF,所以我会非常感谢你的帮助。

在java中,我编写了以下方法:

代码语言:javascript
复制
private void Login()
{
  HttpClient httpClient = new DefaultHttpClient();
  try
  {
      String url = "http://192.168.1.5:8000/Login?username=test&password=test";

    HttpGet method = new HttpGet( new URI(url) );
    HttpResponse response = httpClient.execute(method);
    if ( response != null )
    {
      Log.i( "login", "received " + getResponse(response.getEntity()) );
    }
    else
    {
      Log.i( "login", "got a null response" );
    }
  } catch (IOException e) {
    Log.e( "error", e.getMessage() );
  } catch (URISyntaxException e) {
    Log.e( "error", e.getMessage() );
  }
}

private String getResponse( HttpEntity entity )
{
  String response = "";

  try
  {
    int length = ( int ) entity.getContentLength();
    StringBuffer sb = new StringBuffer( length );
    InputStreamReader isr = new InputStreamReader( entity.getContent(), "UTF-8" );
    char buff[] = new char[length];
    int cnt;
    while ( ( cnt = isr.read( buff, 0, length - 1 ) ) > 0 )
    {
      sb.append( buff, 0, cnt );
    }

      response = sb.toString();
      isr.close();
  } catch ( IOException ioe ) {
    ioe.printStackTrace();
  }

  return response;
}

但到目前为止,在服务器端,我还没有弄清楚任何事情。

如果有人能解释如何创建一个合适的方法字符串登录(字符串用户名,字符串密码)与适当的App.config设置和接口与适当的OperationContract签名,以便从客户端读取这两个参数和回复会话字符串,我将非常感谢。

谢谢!

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/669764

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档