我有一個由IIS中託管的WCF服務引用的程序集。程序集使用一些XSLT文件,我很困惑在哪裏轉儲這些文件,或者在程序集項目本身或WCF服務端創建一個文件夾,以及如何獲取程序集中xslt文件的物理路徑?在wcf服務程序集中獲取文件的路徑
回答
將它們放在引用程序集的子文件夾中,將它們標記爲內容並啓用複製到輸出目錄。
然後,在你需要的文件路徑彙編代碼,獲得執行的程序集的路徑,並添加預期的子文件夾的路徑,例如:
var dllPath = Path.GetDirectoryName(
System.Reflection.Assembly.GetExecutingAssembly().Location);
var targetPath = Path.Combine(dllPath, "XsltFolder");
我已經完成了你說的,但我得到以下錯誤找不到部分路徑爲'C:\ WINDOWS \ Microsoft.NET \ Framework \ v4.0.30319 \ Temporary ASP.NET Files \ root \ d5e86da5 \ 28c7474e \ assembly \ dl3 \ e3edeed7 \ 4bb2927d_561fcc01 \ AV.BackOffice.Caliber.DLL \ XSLTs \ Violations.xslt」。 GetExecutingAssembly()。Loaction沒有返回我認爲的預期路徑,而是將XSLTs文件夾複製到調試目錄。 – VJAI 2011-05-31 05:56:41
因爲IIS託管WCF服務只傾向於將DLL複製到臨時文件夾,而不是複製設置爲輸出的項目的內容,需要引用dll的實際代碼庫。
var codeBase = System.Reflection.Assembly.GetCallingAssembly().CodeBase;
codeBase = codeBase.Substring(8); //Remove the "file:///" prefix in front of the actual path.
var dir = codeBase.Substring(0, codeBase.LastIndexOf("/", System.StringComparison.Ordinal) + 1); //Cut out the dll file name.
var file = @"ErrorMessages.xml";
var targetPath = dir + file;
我有Service.Host.dll和SvcImpl.dll(<%@ ServiceHost服務=「SvcImpl」%>) IIS中的服務主機。 SvcImpl.dll中的此代碼: 1)Assembly.GetEntryAssembly()獲取null。 2)Assembly.GetExecutingAssembly()獲取SvcImpl。 3)Assembly.GetCallingAssembly();獲取System.ServiceModel。 如何在SvcImpl中以編程方式獲取Service.Host程序集,如果Assembly.GetEntryAssembly()獲取null ?.查看詳細信息http://stackoverflow.com/questions/22691426/get-svchost-assembly-location-path-using-svcimplementation-assembly – Kiquenet 2014-04-01 06:54:11
嘗試使用AppDomain.CurrentDomain.RelativeSearchPath
任何XSLT,或XML文件應該被相對於WCF服務文件夾的根文件夾放置,根文件夾,可以實現如下:
如果( HttpContext.Current!= null) //「〜/」給出WCF服務的虛擬目錄的根物理文件夾,這個Biz DLL支持..., //例如:E:\ PhyPath \ WCFServiceFolder \ RequestPhysicalPath = HttpContext.Current.Server。在MapPath( 「〜/」); }
- 1. 在wcf服務中獲取文件的物理路徑
- 2. 在Centennial應用程序中獲取文件的文件路徑
- 3. Java - 獲取「程序文件」路徑
- 4. 路徑重寫WCF服務
- 5. 在WCF Web服務中訪問文件的完整服務器路徑
- 6. 程序作爲服務運行時獲取文件夾的路徑
- 7. 在Cocoa應用程序中獲取文件夾的路徑
- 8. 獲取wcf服務的exe完整路徑
- 9. 如何在Azure服務結構中獲取文件的文件路徑
- 10. 如何獲取Web服務應用程序的「日誌」路徑?
- 11. 在java中獲取文件的路徑
- 12. VBS - 獲取程序文件的文件夾路徑?
- 13. 獲取文件的路徑
- 14. 如何從servlet獲取JSP的服務器文件路徑?
- 15. 獲取Windows服務的完整路徑
- 16. 如何獲取winforms應用程序中的文件路徑
- 17. 服務器中的文件路徑
- 18. 在Python中獲取絕對文件路徑的目錄路徑
- 19. 如何獲取ftp服務器中文件或文件夾的路徑?
- 20. 在c中獲取文件路徑#
- 21. 在java中獲取文件路徑
- 22. 在Python中獲取文件路徑2.7
- 23. 獲取包含32位程序的「程序文件」文件夾的路徑
- 24. 獲取遠程文件路徑位置
- 25. 以獲取部署在jboss SOA服務器中的war文件的路徑
- 26. WCF:同一程序集中的服務調用服務
- 27. 使用回形針獲取服務器文件路徑
- 28. 如何獲取服務可執行文件路徑
- 29. asp:FileUpload獲取文件路徑
- 30. html5獲取文件路徑
關於它的任何最終解決方案?我有類似的問題http://stackoverflow.com/questions/22691426/get-svchost-assembly-location-path-using-svcimplementation-assembly – Kiquenet 2014-03-28 08:40:41