![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
class Program { static void Main(string[] args) { var a = JsonConvert.SerializeObject(new { b = 1999 }); var r = HttpHelper.PostRequest("http://localhost:5829/Service1.svc/GetData", DataTypeEnum.Json, a); Console.WriteLine(r); Console.ReadKey(); } }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
[ServiceContract] public interface IService1 { [OperationContract] [WebInvoke(UriTemplate = "GetData", Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)] string GetData(MyClass b); }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
public class Service1 : IService1 { public string GetData(MyClass b) { return string.Format("You entered: {0}", b.b); } } public class MyClass { public int b { get; set; } }
web.config添加配置
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<service name="WcfService1.Service1"> <endpoint address ="" binding="webHttpBinding" contract="WcfService1.IService1" behaviorConfiguration="web" > </endpoint> </service> <endpointBehaviors> <behavior name="web"> <webHttp/> </behavior> </endpointBehaviors>
返回结果