开发者

List the UriTemplate of WCF operation contracts?

Does anyone know a way of listing the UriTemplate's of the various operation contracts in WCF? What I wan开发者_如何学Got 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜