简体   繁体   中英

Get the version of Service hosted in IIS

We are hosting a WCF service in IIS. For tracking purposes we need to know the version of the service that's being hosted in IIS.

This service is part of an suite of services so we implemented all common functionality (Like the mentioned tracking service in a common library)

When trying to get the Assembly version using normal calls Assembly.GetExecutingAssembly()

  • Assembly.GetExecutingAssembly(): get the version of the common Library
  • Assembly.GetEntryAssembly(): null
  • Assembly.GetCallingAssembly(): get the version of the common library

I also tried getting the call stack and getting the last one (got the IIS version).

Does anyone know how to programmatically get the version of the WCF service that is hosted in IIS?

I am assuming that you need to get the WCF service's version from within common library dll that is referenced by the WCF service at runtime. If not, I don't understand why you would get the common library assembly by running Assembly.GetExecutingAssembly() .

If that is the case, then you want to find the assembly containing the Application object that IIS is running. By using the standard reflection methods on that root Application object, you should get a reference back to the dll that IIS is executing, which should be the WCF service.

Documentation for Application class:

http://msdn.microsoft.com/en-us/library/ms525360(v=vs.90).aspx

This looks like a promising way to get it:

http://msdn.microsoft.com/en-us/library/system.windows.application.current(v=vs.110).aspx

When talking about versions of WCF services, more likely you will realize you want versioning of Web services, rather than assembly version, though you mix both in your question.

The assembly version is of implementation details, and there are no legitimate case that you need to expose such implementation details through either Web services or IIS. IIS itself is of deployment detail, and has nothing to do with versioning of Web services.

System.Windows.Application is of WPF, has nothing to do with WCF or Web service.

When you learned programming, probably you had learned the once an interface is published, you should never alter it, though you could change implementation or introduce new versions of the interface. a Web service is basically an API or interface through http binding, and the description language is typically WSDL for SOAP base Web service.

In a nutshell, versioning of Web service is done through Xml namespace, and in .NET, you could have a mapping between XML namespace and CLR namespace. During deployment, you could have multiple versions of the same service being hosted in the host, so legacy clients could consume the legacy services, and new clients could consume the new versions. So you will have seamless transition strategy.

There's no direct link between assembly versions and service versions, and you should not expose assembly versions, since the clients say PHP or Java clients do not know what assembly version is.

For more details of starting points, here are a few good links if you google "Web service versioning": http://www.ibm.com/developerworks/webservices/library/ws-version/ http://www.oracle.com/technetwork/articles/web-services-versioning-094384.html http://msdn.microsoft.com/en-us/library/ms731060(v=vs.110).aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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