.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添加配置web

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

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

 返回結果ide

相關文章
相關標籤/搜索