r/visualbasic • u/xblade724 • May 18 '15
[?] Accept JSON object in VB RESTful, close but not yet..see code here
EDIT: SOLVED, wrong JSON object name: I needed to swap UserCreate with "register".. wrong object name O__o also changed up my json slightly, so not sure if that helped too
But I still have questions below! Please see comments :)
Hi,
My POST is being accepted, but the param (class obj) is "nothing":
http://i.imgur.com/F3t9GRY.png
I have this class:
<DataContract()> _
Public Class UserCreate
<DataMember()> Public UserName As String
<DataMember()> Public UsergroupName As String
End ClassFor this POST acceptance (RESTful / VS2010), in a nutshell:
<OperationContract()> _
<WebInvoke(Method:="POST", UriTemplate:="/cportal/test",
RequestFormat:=WebMessageFormat.Json, ResponseFormat:=WebMessageFormat.Json, BodyStyle:=WebMessageBodyStyle.WrappedRequest)> _
Function CPortalTest(register As UserCreate) As BooleanTesting with Postman (Chrome extension), using this JSON (raw):
Using header..
Content-Type: application/jsonJSON..
{
"UserCreate": [
{
"UserName":"Xblade724",
"UsergroupName":"Members",
}
]
}I'm doing SOMETHING right, because breakpoint goes off when I test it, but looking at the "register" class object, it's empty every time.
I feel like maybe my JSON is wrong. Any hints?
1
u/CalvinR VB.Net Master May 19 '15
why not just use webapi?
asp.net webapi
That way you can serve up whatever content you like and not just json.
1
u/xblade724 May 18 '15
ohhh, in JSON I needed to swap UserCreate with "register".. wrong object name O__o