近來需要把一個asp.net的網站部署到linux下。
asp.net使用的是mvc3架構,其中也有webservice和wcf服務。
至於mono安裝云云就不說了,網上很多。
下面幾個問題有些我也沒有解決。但網站是正常跑起來了。
第一次放上去時就出現無法編譯的問題:
Compilation Error
Description: Error compiling a resource required to service this request. Review your source file and modify it to fix this error.
Compiler Error Message: : at System.Reflection.AssemblyName..ctor (System.String assemblyName) [0x00045] in /data/tmp/mono-2.10/mcs/class/corlib/System.Reflection/AssemblyName.cs:93
~/Global.asax
Show Detailed Compiler Output:
Version information: Mono Runtime Version: 2.10 (tarball Fri May 4 11:10:52 CST 2012); ASP.NET Version:4.0.30319.
好吧,這問題我頭痛了,可能是以前建項目的問題,我重新建立項目再把以前的檔案加進來。結果好了。我就不管這個了
下面又碰到問題了,網站中有個webservice,死活訪問不了,一直報:
System.Web.Compilation.CompilationException CS1703: An assembly with the same identity `mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' has already been imported. Consider removing one of the references Description: Error compiling a resource required to service this request. Review your source file and modify it to fix this error. Details: CS1703: An assembly with the same identity `mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' has already been imported. Consider removing one of the references Error origin: Compiler Error source file: ~/DefaultWsdlHelpGenerator.aspx Exception stack trace: at System.Web.Compilation.AssemblyBuilder.BuildAssembly (System.Web.VirtualPath virtualPath, System.CodeDom.Compiler.CompilerParameters options) [0x00000] in :0 at System.Web.Compilation.AssemblyBuilder.BuildAssembly (System.Web.VirtualPath virtualPath) [0x00000] in :0 at System.Web.Compilation.BuildManager.GenerateAssembly (System.Web.Compilation.AssemblyBuilder abuilder, System.Web.Compilation.BuildProviderGroup group, System.Web.VirtualPath vp, Boolean debug) [0x00000] in :0 at System.Web.Compilation.BuildManager.BuildInner (System.Web.VirtualPath vp, Boolean debug) [0x00000] in :0 Version Information: 2.11.1 (tarball Wed May 9 23:15:56 CST 2012); ASP.NET Version: 4.0.30319.17020
這我也悲據了,在windows下的mono都能跑,但一放到linux下就出這個,我也沒有解決,直接換成wcf.嗯。。OK了。雖然webservice切成wcf很簡單,但我還是鬱悶。webservice為啥就不行了呢。好了正常了就算了。我也懶得管它。WCF用起來也不錯。
哎。下面這個問題我最蛋痛了,網站中 要引用其它webservice和wcf.
一般情況下我們直接引用進來,new一個client即可訪問了,但linux下死活也不行。
System.Reflection.ReflectionTypeLoadException The classes in the module cannot be loaded. Description: HTTP 500.Error processing request. Details: Non-web exception. Exception origin (name of application or object): mscorlib. Exception stack trace: at (wrapper managed-to-native) System.Reflection.Assembly:GetTypes (System.Reflection.Assembly,bool) at System.Reflection.Assembly.GetTypes () [0x00000] in :0 at System.ServiceModel.Configuration.ConfigUtil.GetTypeFromConfigString (System.String name, NamedConfigCategory category) [0x00000] in :0 at System.ServiceModel.ChannelFactory.ApplyConfiguration (System.String endpointConfig) [0x00000] in :0 at System.ServiceModel.ChannelFactory.InitializeEndpoint (System.String endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) [0x00000] in :0 at System.ServiceModel.ChannelFactory`1[JM.Common.Examples.web.monoserver.Itest2]..ctor (System.String endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) [0x00000] in :0 at System.ServiceModel.ClientBase`1[JM.Common.Examples.web.monoserver.Itest2].Initialize (System.ServiceModel.InstanceContext instance, System.String endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) [0x00000] in :0 at System.ServiceModel.ClientBase`1[JM.Common.Examples.web.monoserver.Itest2]..ctor (System.ServiceModel.InstanceContext instance, System.String endpointConfigurationName) [0x00000] in :0 at System.ServiceModel.ClientBase`1[JM.Common.Examples.web.monoserver.Itest2]..ctor (System.ServiceModel.InstanceContext instance) [0x00000] in :0 at System.ServiceModel.ClientBase`1[JM.Common.Examples.web.monoserver.Itest2]..ctor () [0x00000] in :0 at JM.Common.Examples.web.monoserver.Itest2Client..ctor () [0x00000] in :0 at JM.Common.Examples.web.testserver.Page_Load (System.Object sender, System.EventArgs e) [0x00000] in :0 at System.Web.UI.Control.OnLoad (System.EventArgs e) [0x00000] in :0 at System.Web.UI.Control.LoadRecursive () [0x00000] in :0 at System.Web.UI.Page.ProcessLoad () [0x00000] in :0 at System.Web.UI.Page.ProcessPostData () [0x00000] in :0 at System.Web.UI.Page.InternalProcessRequest () [0x00000] in :0 at System.Web.UI.Page.ProcessRequest (System.Web.HttpContext context) [0x00000] in :0
除了這個外還報過一個key為空白的錯,同樣是找不到引用中的一些配置。
那我只有試試手動new了,
- var binding = new BasicHttpBinding("BasicHttpBinding_Itest2");
- var epa = new EndpointAddress("http://127.0.0.1:8080/test2.svc");
- var client = new monoserver.Itest2Client(binding,epa);
- var r = client.DoWork();
BasicHttpBinding_Itest2就是webconfig中的binding配置名,如此順利跑通了。這個問題確實讓我不解,難道mono不能自動去讀取的麼。非要我手動執行個體化,微軟的.net就沒有這問題。
引用webservice也是如些。必須手動去執行個體化才不出錯。以windows下的想法搞不定它啊
最後一個問題就是mvc3中。我們經常用model去產生頁面控制項。這樣當提交時,後台可直接用model.XX讀取這個控制項的值。
但在linux下的mono卻不行,model的屬性全是空,非得自已寫<input 等等。後台request.Form["name"]去擷取。
這個問題可能是mono下的mvc就是不支援這樣吧。
以上問題如果有大蝦知道更好的解決辦法的話。可以告知小生,THS