Im trying to create a POST method for my AddTagtoGroup
which looks like this (altho still confused as string group never seems to be used):
List<Group> Groups = new List<Group>();
List<Tag> tags = new List<Tag>();
public void AddTagtoGroup(string group, string tag)
{
var result = Groups.Where(n => String.Equals(n.GroupName, tag)).FirstOrDefault();
if (result != null)
{
result.Tags.Add(new Tag() { TagName = tag });
}
}
And my post method looks like this but im unsure what to put in the uri template?
[OperationContract]
[WebInvoke(Method = "POST",
BodyStyle = WebMessageBodyStyle.Bare,
RequestFormat = WebMessageFormat.Xml,
ResponseFormat = WebMessageFormat.Xml,
UriTemplate = "/AddTagtoGroup{group}{tag}")]
void AddTagtoGroup(string group, string tag);
Or am I getting confused with GET and anything can go in the uri template?
Altho upon running my post with just bare as the message formatt I get the error saying that my operation contract must be wrapped so I changed this to WebMessageFormat.Wrapped
The uri template I just set to UriTemplate="/AddTagtoGroup" it runs but im not sure I can actually post anything to it or can I? Like I say bit confused with GET & POST.
If you’d like to be restful you have a couple of options.
If it is just strings, you want to define it as follows. Note that there is no data contracts needed. The downside is that if you have 100 tags, you’ll have to make a 100 calls.
To batch them up, you can do the following:
Now, there are some problems with this too, in particular if you’d like your payload to be self describing like:
In this case I’d define a data contract Tag as you did and post it as follows:
Or wrap the tags request as follows:
and define the signature as follows:
The choice is really yours. The WCF REST help page will give you the exact format to post.