Reputation: 832
I'm creating WCF Web Service, which should be consumed by applications using URL only (e.g. http://localhost:8000/TestMethod?s=testString
).
I have successfully hosted this web service, it works well etc. But for now, I'm passing only simple values there.
For example, having next example
[DataContract]
public struct Person
{
[DataMember]
public string FirstName;
[DataMember]
public string LastName;
}
//in service interface
[OperationContract]
[WebInvoke]
void RegisterUser(Person newUser);
How should I call RegisterUser
using URL? How will stucture parameter look? Or should I simply decompose data type to simple variables and pass them as parameters?
Upvotes: 0
Views: 404
Reputation: 7009
Set Uri template to the method, so that service identify the method to execute and understand the data passed via URL.
Have a look at documentation
https://msdn.microsoft.com/en-us/library/system.servicemodel.web.webinvokeattribute(v=vs.110).aspx
For passing complex type pass json string (prefer post rather than get) and user serializer to deserialize the string to person object.
or Consider different requestType https://msdn.microsoft.com/en-us/library/system.servicemodel.web.webinvokeattribute.requestformat(v=vs.110).aspx
Upvotes: 1