Does anyone know a way of listing the UriTemplate's of the various operation contracts in WCF? What I want to do is to somehow at IntegrationTesting spin up a selfhosted service and loop through all the operation contracts and print the UriTemplates if at all possible.
+3
A:
Do you mean the Action? There is no UriTemplate property on OperationContract.
If yes, you can use reflection to get the Methods of the type and from each method get the OperationContractAttribute to get it's Action property.
var methods = typeof (IService1).GetMethods();
IEnumerable<string> actions = methods.Where(
m => m.GetCustomAttributes(typeof (OperationContractAttribute), true).Count() > 0)
.Select(m =>
((OperationContractAttribute)m.GetCustomAttributes(typeof (OperationContractAttribute), true).First()).Action);
Console.WriteLine(string.Join("\r\n",actions.ToArray()));
EDIT: as marc mentions, you may be after WebGet, so replace OperationContractAttribute
with WebGetAttribute
and Action
with UriTemplate
or whatever property you would like to see.
Sky Sanders
2010-02-13 17:02:18
WCF REST method have both an [OperationContract] and a [WebGet] attribute on each method, basically. I think that's what the OP is after.
marc_s
2010-02-13 17:13:01
Thanks, Marc, I haven't yet explicitly used REST much but now that you mention it...
Sky Sanders
2010-02-13 20:58:00
Not exactly what I was looking for, but I changed the to WebGetAttribute and WebInvokeAttribute and was able to find two problematic Uri templates I would prefer to be able to get that for the running service but as long as I can test it somehow I am happy :)
mhenrixon
2010-02-13 23:30:03
Can get it from the WSDL?
Sky Sanders
2010-02-14 00:49:00
Unfortunately not because calling the WSDL fails because I have operation contracts that takes parameter stream and that makes the WSDL fail unless the stream parameter is the only parameter :) Stupid hey
mhenrixon
2010-02-14 22:58:02
REST calls don't have a WSDL......
marc_s
2010-02-16 06:27:18
[stuffs on more nugget in the noggin]->
Sky Sanders
2010-02-16 06:35:55