当前位置: 移动技术网 > IT编程>开发语言>.net > .net post请求wcf

.net post请求wcf

2019年09月19日  | 移动技术网IT编程  | 我要评论
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添加配置

<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

如您对本文有疑问或者有任何想说的,请 点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网