简体   繁体   English

如何从程序集/ WCF服务中访问程序集版本和名称?

[英]How do I access the assembly version and name from inside the assembly/WCF service?

I would like to provide an operation contract in my WCF library that returns select information, ie version, assembly name, some other internal values. 我想在我的WCF库中提供一个操作契约,它返回选择信息,即版本,程序集名称和一些其他内部值。

The purpose is to provide a "Service Check" method for diagnostics and such that can be called as a regular WCF. 目的是为诊断提供“服务检查”方法,并且可以将其称为常规WCF。

I am having trouble figuring out the best way to do this. 我无法找到最好的方法来做到这一点。 I imagine some sort of internal reflection. 我想象某种内部反思。

I would also like to put this code inside the Interface as part of the operation contract. 我还想将此代码作为操作合同的一部分放在Interface中。

What is the best way to do this? 做这个的最好方式是什么?

You can do this using reflection: 您可以使用反射执行此操作:

For example, to get the assembly's version info: 例如,要获取程序集的版本信息:

return System.Reflection.Assembly.GetExecutingAssembly().GetName().Version

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM