Android使用Ksoap2调用Web service传递自定义对象,List,大文件

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/jylong1110/article/details/69523601

JavaBean,List

调用

1、导入Gson.jar包

2、调用

new Gson().toJson(obj);
new Gson().toJson(list);
将JavaBean或list转换成String类型,其余操作同基本参数一样


解析返回的json参数

Object obj = new Gson().fromJson(str,Object.class);
List<Object> list = new Gson().fromJson(str, new TypeToken<List<Object>>() {}.getType());

其中str是返回的JsonString结果。


大文件,图片、文本等

调用

将图片、文本等转换成byte[]类型

这样上传是不成功的,我们需要在call之前用Base64进行register.

new MarshalBase64().register(envelope);

解析结果数据

如果是Base64需要先进行

 byte[] bytes=Base64.decode(resulObject.getProperty(0).toString());




展开阅读全文

C# web service 返回 自定义对象

09-04

User.cs 代码如下rn***********************************************rnnamespace DataModelrnrn [Serializable()]rn public class [color=#FF0000]User[/color]rn rn public User()rn rn rnrn public User(int id,string name)rn rn id = id;rn name = name;rn rnrn private int id;rnrn public int IDrn rn get return id; rn set id = value; rn rnrn private string name;rnrn public string Namern rn get return name; rn set name = value; rn rnrn #region DB IOrnrn public User RetrunUserSingle(SqlConnection connection)rn rn using (SqlCommand command=connection.CreateCommand())rn rn command.CommandText = "select * from [user] where ID=1";rn SqlDataReader dr = command.ExecuteReader();rn Reader(dr);rn User user =new User(id,name);rn return user;rn rn rnrn public void Reader(SqlDataReader dr)rn rn if (dr.Read())rn rn name = dr.GetString(dr.GetOrdinal("Name"));rn id = dr.GetInt32(dr.GetOrdinal("ID"));rn rn rnrn #endregionrnrn rnrn***********************************************rnwebservice 页面 代码如下rnrn***********************************************rn [WebMethod]rn public [color=#FF0000]User[/color] GetOneUser(SqlConnection connection)rn rn User user = new User();rn return user.RetrunUserSingle(connection);rn rn***********************************************rn总是报错,错误信息:rnCannot serialize member System.ComponentModel.Component.Site of type System.ComponentModel.ISite because it is an interface.rnrn希望赐教,越详细越好!rn 论坛

没有更多推荐了,返回首页