欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

.net post请求wcf

程序员文章站 2022-07-01 23:30:58
class Program { static void Main(string[] args) { var a = JsonConvert.SerializeObject(new { b = 1999 }); var r = HttpHelper.PostRequest("http://localh ......
    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);
    }
    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添加配置

.net post请求wcf

<service name="wcfservice1.service1">
        <endpoint address ="" binding="webhttpbinding" contract="wcfservice1.iservice1" behaviorconfiguration="web" >
        </endpoint>
      </service>

 <endpointbehaviors>
        <behavior name="web">
          <webhttp/>
        </behavior>
      </endpointbehaviors>

 返回结果

.net post请求wcf

 .net post请求wcf