Android WCF Restful 服务续

前段时间写了一篇Android WCF调用入门的学习博客,然后自以为可以搞定 。最近群里碰见一朋友讨论这个事情:POST 传参数的老是出错。所以感觉自己不是很踏实,应该将基础的操作完成,所以有了这篇。

WCF 对Restful服务提供了很好的支持,通过引用System.ServiceModel.Web命名空间下的一些属性完成配置,目前只知道WebGetAttribute和WebInvokeAttribute。如果有什么其他好方法,大家一起探讨。

为了测试多种传入和传出方式,Wcf服务接口:如下

using System.ServiceModel;
using System.ServiceModel.Web;
namespace RestfulWcfDemo
{
    // 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码和配置文件中的接口名“IService1”。
    [ServiceContract]
    public interface IOperationAPi
    {
        [OperationContract]
        [WebGet(UriTemplate = "SimpleCall",ResponseFormat =WebMessageFormat.Json)]
        string SimpleCall();

        [OperationContract]
        [WebInvoke(UriTemplate = "SimpleCallWithPara/{para}", ResponseFormat = WebMessageFormat.Json,Method ="GET")]
        string SimpleCallWithPara(string para);

        [OperationContract]
        [WebInvoke(UriTemplate = "SimpleCallBackEntity", ResponseFormat = WebMessageFormat.Json, Method = "GET")]
        Person SimpleCallBackEntity();

        [OperationContract]
        [WebInvoke(UriTemplate = "SimpleCallPost", ResponseFormat = WebMessageFormat.Json,RequestFormat =WebMessageFormat.Json, Method = "POST")]
        string SimpleCallPost(Person person);

        [OperationContract]
        [WebInvoke(UriTemplate = "SimpleCallPut/{para}", ResponseFormat = WebMessageFormat.Json, Method = "PUT")]
        string SimpleCallPut(string para, Person person);

        [OperationContract]
        [WebInvoke(UriTemplate = "SimpleCallDelete/{para}", ResponseFormat = WebMessageFormat.Json, Method = "DELETE")]
        string SimpleCallDelete(string para);
    }
}
Andoriod界面如下:

,成功测试了上述设计的几个接口。

附上Android源码以及服务源码,有问题或者其他好办法的友们,一起研究。

WCF 服务:http://download.csdn.net/detail/casetime/9453614

AndroidDemo:http://download.csdn.net/detail/casetime/9453616

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值