【发布时间】:2010-10-14 18:16:44
【问题描述】:
我正在.NET 中创建服务器和Android 客户端应用程序。我想实现一种身份验证方法,将用户名和密码发送到服务器,服务器发回会话字符串。
我不熟悉 WCF,因此非常感谢您的帮助。
在java中我写了以下方法:
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] 签名的接口创建适当的方法字符串登录(字符串用户名,字符串密码),以便从客户端读取这两个参数,我将非常感激并回复会话字符串。
谢谢!
【问题讨论】:
-
我很想看到一种使用在 android 上序列化的 wcf 二进制文件的方法。现在那会很酷。