WCF Rest Json

时间:2014-05-06 01:03:39   收藏:0   阅读:383

1、定义ServiceContract及实现

bubuko.com,布布扣
    [ServiceContract]
    public interface IMemberService
    {
        [OperationContract]
        string GetData(int value);

        [OperationContract]
        CompositeType GetDataUsingDataContract(CompositeType composite);

        [OperationContract]
        [WebInvoke(Method = "POST", UriTemplate = "/create", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
        string CreateMember(Member member);

        [OperationContract]
        [WebGet(UriTemplate = "all")]
        string GetAll();
        // TODO: 在此添加您的服务操作
    }
bubuko.com,布布扣

2、svc文件

bubuko.com,布布扣
<%@ServiceHost language=c# Debug="true" Service="WebApplication1.MemberService" Factory="System.ServiceModel.Activation.WebServiceHostFactory"%>
bubuko.com,布布扣

3、Fiddler测试

bubuko.com,布布扣
Request Headers:

User-Agent: Fiddler
Content-Type: application/json;charset=UTF-8
Host: localhost:4087
Content-Length: 45


RequestBody:
{"member":{"ID":"Brett","Name":"McLaughlin"}}
bubuko.com,布布扣

 

WCF Rest Json,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!