2011-08-08 40 views
1

是否可以在Web服務描述中顯示修訂/內部版本號? 我希望用戶在轉到web服務的url時查看當前正在運行的版本。C#在web服務描述中顯示修訂/內部版本號?

Ex。

[WebService(Namespace = "http://webservice.mydomain.com/", Name = "webservice for multimedia devices", Description = "Last build: **xxxxx**")] 

我要動態地得到它,如果可能的(System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()

我也試過這個(建議見下文)。這得到了描述,但它在向客戶端顯示web服務之前無法更新它。

var t = typeof(webClient); 
var att = (WebServiceAttribute)t.GetCustomAttributes(typeof(WebServiceAttribute), true)[0]; 
att.Description = "Current running version: " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; 

回答

1

我還沒有證實此事,但是試試這個:

WebServiceAttribute att = (NamespaceAttribute)t.GetCustomAttributes(WebServiceAttribute))[0]; 

att.Description = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); 

這是在啓動過程中一些合適的點來完成。

+0

似乎不起作用。我添加了這個:var t = typeof(webClient); var att =(WebServiceAttribute)t.GetCustomAttributes(typeof(WebServiceAttribute),false)[0]; att.Description =「當前正在運行的版本:」+ System.Reflection.Assembly.GetExecutingAssembly()。GetName()。Version; – Patrick

+0

這得到了描述,但沒有更新它。我忘了提及我使用.NET 3.5而不是4. – Patrick

+0

您是否嘗試在自定義ServiceHostFactory中添加此代碼(http://msdn.microsoft.com/zh-cn/library/system.servicemodel.activation.servicehostfactory。 ASPX)?我認爲這應該工作。 – Peter

0

你可以,但你需要先手動定義程序集信息和版本,然後使用反射在運行時恢復它。默認情況下,除非您自己定義它,否則似乎沒有ASP.NET應用程序的「版本號」概念。

本文演示如何做到這一點。文章展示瞭如何獲得更多的不僅僅是版本#,而是它在那裏。

http://wiki.lessthandot.com/index.php/ASP.NET:_Display_Version_Information

+0

問題依然存在。我需要在web服務描述中介紹這一點。 – Patrick