.net post请求wcf

    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();
        }
    }
控制台调用
    [ServiceContract]
    public interface IService1
    {

        [OperationContract]
        [WebInvoke(UriTemplate = "GetData", Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)]
        string GetData(MyClass b);
    }
wcf接口配置
    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; }
    }
wcf实现

web.config添加配置

<service name="WcfService1.Service1">
        <endpoint address ="" binding="webHttpBinding" contract="WcfService1.IService1" behaviorConfiguration="web" >
        </endpoint>
      </service>

 <endpointBehaviors>
        <behavior name="web">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
web.config相关配置

 返回结果

 

.net post请求wcf

全文结束