zoukankan      html  css  js  c++  java
  • .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相关配置

     返回结果

  • 相关阅读:
    ES6 Set.Map.Symbol数据结构
    ES6 class类 静态方法及类的继承
    ES6 浅谈Reflect
    ES6 proxy代理详解及用法
    Vue之生命周期函数
    Vue之自定义键盘修饰符、自定义指令
    v-show和v-if区别
    迭代器iterator
    es6之Proxy代理
    es6之symbol数据类型
  • 原文地址:https://www.cnblogs.com/jxp0202/p/11540260.html
Copyright © 2011-2022 走看看