WCF服务返回JSON格式数据、配置web调用地址

 

        /// 为了支持多个参数,还需要设置BodyStyle为WrappedRequest。

 

有多种url形式: --/UserNameEnable?f={UserName}

                          --/UserNameEnable?name={UserName}&pwd={pwd}

或者:       多个参数 UriTemplate=/Login/{name}/{pwd} 

                 第二个参数选填UriTemplate=/Login/{name}/{*pwd}

                 第二个参数默认值UriTemplate=/Login/{name}/{pwd=123456}

        [OperationContract]

        [WebGet(UriTemplate = "/GetData/{UserName}",

                         ResponseFormat = WebMessageFormat.Json,

                        RequestFormat = WebMessageFormat.Json,

                        BodyStyle = WebMessageBodyStyle.WrappedRequest)]

                    Student  GetData(string UserName);

 Config配置:

 1、 <service name="MT4_CRM.WcfService.UserMoblie">
        <endpoint address="" behaviorConfiguration="httpBehavior" binding="webHttpBinding" bindingConfiguration="basicTransport" contract="MT4_CRM.WcfService.Interface.IUserMoblie"/> <!--提供WebGet服务用-->

        <endpoint address="Wcf" binding="basicHttpBinding" contract="MT4_CRM.WcfService.Interface.IUserMoblie"/>
        <!--提供WCF服务 , 注意address='Wcf',为了区分开与WebGet的地址,添加引用之后会自动加上的-->

        <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex"/>
        <!--元数据-->
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8733/Service/" />
          </baseAddresses>
        </host>
      </service>

2、

<behaviors>

<endpointBehaviors>
        <behavior name="httpBehavior">
          <webHttp />
        </behavior>
</endpointBehaviors>

</behavior>

3、

<bindings>
       <webHttpBinding>
        <binding name="basicTransport"/>
      </webHttpBinding>
 </bindings>

 

web调用地址:http://localhost:8733/Service/GetData/张三

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值