c# - Parse Json Data in wcf Rest? -
i want create wcf rest service accept json data , parse value.
my json data coming client side this:
{"user":{"username":"123","pass":"123"}}
i create simple wcf operationcontract :
[operationcontract] [webinvoke(method = "post", uritemplate = "login", bodystyle = webmessagebodystyle.wrapped, responseformat = webmessageformat.json, requestformat = webmessageformat.json )] string login(user user);
what can in login method parsing json data??
if send data client this:
{"username":"123","pass":"123"}
you have class
class user{ public string username {get;set;} public string pass {get;set;} }
if client insist on request :
{"user":{"username":"123","pass":"123"}},
you should have class:
class user{ public string username {get;set;} public string pass {get;set;} }
class requestj{ public user user{get;set;} }
and must change wcf service :
[operationcontract] [webinvoke(method = "post", uritemplate = "login", bodystyle = webmessagebodystyle.wrapped, responseformat = webmessageformat.json, requestformat = webmessageformat.json )] string login(requestj user);
Comments
Post a Comment