WCF中操作契约 BodyStyle和XML, Json格式的学习

今天研究了一下在之前在帖子Android访问WCf得到的奇怪JSON中提到的问题, 发现跟其于操作契约中设置的BodyStyle有关, 详细参阅[WCF REST] Web消息主体风格(Message Body Style)

在这里做一下记录: 

endpointBehaviors

<behavior name="webScript">
	<enableWebScript />
</behavior>            
<behavior name ="webHTTP">
	<webHttp/>
</behavior>
endpoint

<!--原来是webScript-->                
<endpoint address="" binding="webHttpBinding" contract="Host.IAndroidServices" behaviorConfiguration="webHTTP">
                    <identity>
                        <dns value="localhost"/>
                    </identity>
                </endpoint>

操作契约

        [OperationContract]
        [WebInvoke(
            BodyStyle = WebMessageBodyStyle.WrappedRequest,
            ResponseFormat = WebMessageFormat.Json,
            RequestFormat = WebMessageFormat.Json)]
        RetUserInform logIn(string userID, string PWD);

操作契约实现

        #region IAndroidServices Members logIn

        public RetUserInform logIn(string userID, string PWD)
        {
            Console.WriteLine("logIn has bean satared");
            RetUserInform n = new RetUserInform();
            n.Userid = 123456;
            n.Functions = "asdfads";
            n.UserAreaCode = "012";
            n.FinalDate = "afd";
            return n;
        }

        #endregion
之前得到格式为
{"d":{"__type":"RetUserInform:#Host","FinalDate":"afd","Functions":"asdfads","UserAreaCode":"012","Userid":123456}}

的JSON串是由于对Response的包装导致的, 作出如上修改后得到

{"FinalDate":"afd","Functions":"asdfads","UserAreaCode":"012","Userid":123456}

一切正常.



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值