设为首页 加入收藏

TOP

.net post请求wcf
2019-09-19 11:10:52 】 浏览:52
Tags:.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

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇.net post请求webservice 下一篇C#上手练习1(if语句、Swich语句)

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目