简体   繁体   中英

RESTful WCF Services with No svc file and No config with parameter binding

I already setup the service with No svc file and No config but I need binding parameter with json, I try using postman(google extension) to get in, and I always getting min date in my object class. Isn't possible to do it?

For exmaple:

{ "date" : { "lastdate" : "2012-02-02"}}

this json will binding into method class.

Header

POST /DMatchService/Team HTTP/1.1
Host: localhost:10017
Content-Type: application/json
Accept: application/json
Cache-Control: no-cache

{ "Team" : { "lastdate" : "1335205592410"}}

Services classes

 [OperationContract]
 [WebInvoke(UriTemplate = "GetTeam", Method = "POST")]
 public string GetTeam(Team team)
  {
       DatasourceMatchServices svc = new DatasourceMatchServices();
       return date.lastdate.ToString();
   }

Classes

[DataContract]
    public class Team
    {
        [DataMember]
        public DateTime lastdate { get; set; }
    }

Global.cs

protected void Application_Start(object sender, EventArgs e)
        {

            RouteTable.Routes.Add(new ServiceRoute("DMatchService", new WebServiceHostFactory(), typeof(DMatchService)));

        }

您可以通过ajax调用将数据作为json postendpoint 。在这种情况下,我认为您不需要DataContract attributes

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM