0
<HttpGet()>
Public Function Search(<FromUri()> ByVal name As Name) As HttpResponseMessage
  // get params from complex type
  // or check for model validation
  name.firstName;
  name.lastName;
End Function

Public Class Name
 <Required()>
 Public firstName As String
 <Required()>
 Public lastName As String
End Class

/api/abc/search?firstName=jack&lastName=daniels

I am trying to send a comlex type as a query parameter but name is always null even though I am using fromUri attribute. What am I missing?

EDIT: I am also using Required() attribute from System.ComponentModel.DataAnnotations .

3
  • This is for a web service right? Do you have a specific example you're working from? From my experience webservice params are parsed individually Commented Sep 8, 2012 at 3:15
  • yes, web service. when I test this as a separate example, it works fine,too. I dont know why it doesnt run in my project. Commented Sep 8, 2012 at 18:19
  • so you're the guy that writes in VB.NET Commented Oct 30, 2015 at 15:10

1 Answer 1

1

I found the problem. I was missing the Property keywords on my fields.

Public Class Name
 <Required()>
 Public firstName As String
 <Required()>
 Public lastName As String
End Class

So, it worked with the following change.

Public Class Name
 <Required()>
 Public Property firstName As String
 <Required()>
 Public Property lastName As String
End Class

The problem solved. I think, without properties, the class does not expose its fields, so I cant read them from uri.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.