i have simple interface that i want to test it out but i have'nt understood when to use URITemplate:
how would i access XMLData in this case...?
[OperationContract]
[WebInvoke(Method = "GET开发者_开发问答",
ResponseFormat = WebMessageFormat.Xml,
BodyStyle = WebMessageBodyStyle.Wrapped)]
string XMLData(string id);
public class RestServiceImpl : IRestServiceImpl
{
public string XMLData(string id)
{
return "my xml data:" + id;
}
UriTemplate is some kind alike of masking your method. Example:
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "myMethod/{id}")]
string XMLData(string id);
you may now call the method this way:
http://localhost/RestServiceImpl/myMethod/inputIdstring
instead of...
http://localhost/RestServiceImpl/XMLData?id=inputIdstring
I hope this helps..
By default, if you don't specify a UriTemplate
, WCF will supply one for you that uses a query string format, such as this:
XMLData?id={id}
However, you might want a RESTful URI, instead, like this:
xmldata/{id}
For those cases, you add a UriTemplate
. If you don't need anything but the default semantics, feel free to leave it off.
精彩评论