做android开发时你还在为gson,json而人肉序列化与反序列化吗,上传文件时你还在使用UrlConnection或者HttpClient吗?
下面提供了asp.net 服务端与 android 客户端通过hessdroid (hessian 的android版) 通信解决方案,从此你不用再为上面的问题发愁了
中小应用,使用.net 的EF(数据库优先)或linq,那是相当的方便,做个管理页面也只要拖拖控件就好了(不拖都对不起自己尤其是自己从头整到尾的项目), 当然你需要使用EmitMapper一类的东西将dto映射到EF实体类上。

服务端定义实体类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web; namespace cn.fstudio.hessian.dto
{
public class ResponseBase<T>
{
private int code;
private string msg;
private T model; public int Code
{
get { return code; }
set { code = value; }
}
public string Msg
{
get { return msg; }
set { msg = value; }
}
public T Model
{
get { return model; }
set { model = value; } }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using cn.fstudio.hessian.dto; namespace aa.model
{ public class UserListResponse:ResponseBase<List<UserInfo>>
{
private DateTime? addTime; public DateTime? AddTime
{
get { return addTime; }
set { addTime = value; }
}
private byte[] fileDate; public byte[] FileDate
{
get { return fileDate; }
set { fileDate = value; }
}
private bool? isAdmin; public bool? IsAdmin
{
get { return isAdmin; }
set { isAdmin = value; }
} }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace aa.model
{
public class UserInfo
{
private string userNo ;
public String UserNo
{
get
{
return userNo;
}
set
{
userNo = value;
}
}
private string username; public string Username
{
get { return username; }
set { username = value; }
}
private string password; public string Password
{
get { return password; }
set { password = value; }
}
private string mobile; public string Mobile
{
get { return mobile; }
set { mobile = value; }
}
private string userType; public string UserType
{
get { return userType; }
set { userType = value; }
}
private int recId; public int RecId
{
get { return recId; }
set { recId = value; }
}
private int userLevel; public int UserLevel
{
get { return userLevel; }
set { userLevel = value; }
} }
}

实体类定义不要写成public String Field{get;set;} //因为只动生成的字段名称可能是FieldName_<>K,hessian反射时会出错

服务端接口定义与实现

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; using aa.model;
namespace aa.service
{
public interface UserService
{
UserListResponse getUserlist(UserListResponse res);
string hello(string name);
List<UserInfo> getUsers();
AInfo getAInfo();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using aa.service;
using aa.model;
using hessiancsharp.server;
namespace AA.ServiceImpl
{
public class UserServiceImpl:CHessianHandler, UserService
{
#region UserService 成员 public UserListResponse getUserlist(UserListResponse res)
{
var response = res; UserInfo u = new UserInfo();
u.Username = "张三";
u.UserLevel = ;
response.AddTime = DateTime.Now; response.Model.Add(u); response.Code = ;
response.Msg = "终于可以了吗吗吗吗?"; return response;
} #endregion #region UserService 成员 public string hello(string name)
{
return DateTime.Now + "->" + name;
}
public List<UserInfo> getUsers()
{
UserInfo u = new UserInfo();
u.Username = "张三";
u.UserLevel = ;
return new List<UserInfo>() { u, u, u, u, u, u, u };
} #endregion #region UserService 成员 public AInfo getAInfo()
{
return new AInfo() { id = ,name="还是中文" };
} #endregion
}
}

注意:mvc项目需要在routeConfig中加上 routes.IgnoreRoute("{hessian}.hessian/{*pathInfo}");
web.config中添加
   <httpHandlers>
      <add verb="*" path="UserService.hessian" type="AA.ServiceImpl.UserServiceImpl, AA.ServiceImpl" />
    </httpHandlers>

 客户端实体类:

package cn.fstudio.hessian.dto;

import java.io.Serializable;

public class ResponseBase<T> implements Serializable{

    private static final long serialVersionUID = 1L;
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public T getModel() {
return model;
}
public void setModel(T model) {
this.model = model;
}
private int code;
private String msg;
private T model;
}
package aa.model;

import java.io.Serializable;
import java.util.Date;
import java.util.List; import aa.model.UserInfo; import cn.fstudio.hessian.dto.ResponseBase; public class UserListResponse extends ResponseBase<List<UserInfo>> implements Serializable { /**
*
*/
private static final long serialVersionUID = 1L;
private Date addTime;
private byte[] fileDate;
private Boolean isAdmin; public Date getAddTime() {
return addTime;
}
public void setAddTime(Date addTime) {
this.addTime = addTime;
}
public byte[] getFileDate() {
return fileDate;
}
public void setFileDate(byte[] fileDate) {
this.fileDate = fileDate;
}
public Boolean getIsAdmin() {
return isAdmin;
}
public void setIsAdmin(Boolean isAdmin) {
this.isAdmin = isAdmin; } }
package aa.model;

import java.io.Serializable;

public class UserInfo implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
public String getUserNo() {
return userNo;
}
public void setUserNo(String userNo) {
this.userNo = userNo;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public String getUserType() {
return userType;
}
public void setUserType(String userType) {
this.userType = userType;
}
public int getRecId() {
return recId;
}
public void setRecId(int recId) {
this.recId = recId;
}
public int getUserLevel() {
return userLevel;
}
public void setUserLevel(int userLevel) {
this.userLevel = userLevel;
}
public static long getSerialversionuid() {
return serialVersionUID;
}
private String userNo;
private String username;
private String password;
private String mobile;
private String userType;
private int recId;
private int userLevel; }

客户端接口定义

package aa.service;

import java.util.List;

import aa.model.AInfo;
import aa.model.UserInfo;
import aa.model.UserListResponse; public interface UserService {
public UserListResponse getUserlist(UserListResponse req);
public String hello(String name);
List<UserInfo> getUsers();
AInfo getAInfo();
}
        String url = "http://122.xxx.xxx.x:7086/UserService.hessian";
HessianProxyFactory factory = new HessianProxyFactory();
try { UserListResponse req=new UserListResponse();
req.setAddTime(new Date());
req.setCode();
req.setFileDate(new byte[]{,,});
req.setIsAdmin(true);
req.setMsg("这里我传了一些中文上去"); UserInfo u=new UserInfo(); u.setUsername("一个鸟人");
u.setMobile("");
u.setUserLevel(); List<UserInfo> list=new ArrayList<UserInfo>();
for(int i=;i<;i++)
{
list.add(u);
} req.setModel(list); factory.setDebug(true);
factory.setReadTimeout( * );
UserService basic = (UserService)factory.create(UserService.class, url,getClassLoader());
String response=basic.hello("xxx");
UserListResponse response2=basic.getUserlist(req);
//Toast.makeText(FullscreenActivity.this, "调用结果:"+ response2.getCode(), Toast.LENGTH_LONG).show();
String msg=response2.getModel().get(response2.getModel().size() -).getUsername() + "," + response2.getModel().size();
new AlertDialog.Builder(FullscreenActivity.this).setTitle(response2.getFileDate().length + "").setMessage(msg).show();
} catch (Exception e) {
new AlertDialog.Builder(FullscreenActivity.this).setTitle("Error").setMessage(e.getMessage()).show();
}

程序参考华位网盘[软件任务与测试]

asp.net hessian + android hessdroid的更多相关文章

  1. asp.net Hessian 服务的注册

    Hessian服务端实现了IHttpHandle, 默认情况下是在Web.Config中的handles接点中注册,这样当有 很多实现时比较麻烦 这个时候可以实现IHttpHandleFactory注 ...

  2. Android ScrollView嵌套ScrollView滚动的问题解决办法

    引用:http://mengsina.iteye.com/blog/1707464 http://fenglog.com/article.asp?id=449 Android ScrollView嵌套 ...

  3. Cheatsheet: 2013 11.12 ~ 11.30

    Mobile Xcode 5 Essentials Android vs. iOS Development: Fight! Using MVC to Understand ASP.NET, iOS, ...

  4. visual studio 2017安装教程以及各类问题解决方案

    文章的关键词和所含教程: VS2017安装/visual studio 2017安装/Xamarin/Android for visual studio 2017/VS2017找不到网站/VS2017 ...

  5. 安卓Webview缓存网页数据(无网络正常显示)

    热度 1已有 52 次阅读2016-8-26 17:53 |个人分类:常见问题|系统分类:移动开发 一.需求经历 最近的项目是一个原生 +webview 显示的 APP,一开始的时候,网站那边要求我们 ...

  6. 在线学编程!十大IT在线教育网站推荐

    在线学编程!十大IT在线教育网站推荐 1.CSDN学院(http://edu.csdn.net/) CSDN学院是CSDN推出的一个面向中国软件开发者和IT专业人员的技术教育服务平台.主要提供IT领域 ...

  7. [转]Android项目快速开发框架探索(Mysql + OrmLite + Hessian + Sqlite)

    前言 结合之前所用的ormlite和hessian,再加上SAE已经支持JAVA,把服务端切换到JAVA,也就有了本文.使用hessian来做数据传输,ormlite来实现客户端与服务端的数据存储,极 ...

  8. 一百元的智能家居——Asp.Net Mvc Api+讯飞语音+Android+Arduino

    大半夜的,先说些废话提提神 如今智能家居已经不再停留在概念阶段,高大上的科技公司都已经推出了自己的部分或全套的智能家居解决方案,不过就目前的现状而言,大多还停留在展厅阶段,还没有广泛的推广起来,有人说 ...

  9. phongap+ jquery + asp.net +android,我把我遇到的问题和处理方法的连接总结一下

    这些都是最基本的问题,在实际的运用中都会用到 第1章.搭建Android的开发环境-跟我学编程 Win7旗舰版中的IIS配置asp.net的运行环境 - 追夢 - 博客园 vs2012下asp.net ...

随机推荐

  1. python中django框架的csrf验证

    在form表单以post的方式提交时,django默认会带一个验证的机制csrf验证 <form action="/day02/login/" method="po ...

  2. ehci ohci 驱动逻辑

    1. EHCI ehci_platform_probe: platform_get_irq usb_hcd_request_irqs usb_hcd_irq 使用的是ehci的irq hcd-> ...

  3. 微信小程序详解——页面之间的跳转方式【路由】和参数传递

    微信小程序拥有web网页和Application共同的特征,我们的页面都不是孤立存在的,而是通过和其他页面进行交互,来共同完成系统的功能.今天我们来研究小程序页面之间的跳转方式. 1.先导 在Andr ...

  4. ThinkJava-输入和输出

    1/0流的典型使用方式   1.缓冲输入文件 package com.java.io; import java.io.BufferedReader; import java.io.File; impo ...

  5. Jquery 插件PrintArea 打印指定的网页区域

    Jquery 插件PrintArea 打印指定的网页区域 需要下载jquery 和printarea.js插件 PrintArea.Js插件,可以打印整个网页中某个指定的区域. $("打印区 ...

  6. Electron 前端页面导入jQuery 出现错误Uncaught ReferenceError: jQuery is not defined

    如下: <script src="../assets/js/jquery-1.10.2.js"></script> 方法1 改为: <script&g ...

  7. MySQL 5.7 免安装版配置

      MySQL5.7免安装版配置 Mysql是一个比较流行且很好用的一款数据库软件,如下记录了我学习总结的mysql免安装版的配置经验. 一. 软件下载 5.7 32位https://dev.mysq ...

  8. html链接路径

    html链接的相对路径与绝对路径 绝对路径 完整的一个路径就是绝对路径,即包含schema://host[:port#]/path/.../[?query-string][#anchor] 例:htt ...

  9. 使用python读取大文件

    python中读取数据的时候有几种方法,无非是read,readline,readlings和xreadlines几种方法,在几种方法中,read和xreadlines可以作为迭代器使用,从而在读取大 ...

  10. Spring IO Platform介绍

    为什么要用Spring IO Platform 今天无意间看到了一个关键词:"Spring IO Platform",第一直觉是不是有关于IO方面的框架或者包呢,查了一下,居然是为 ...