2013-03-11 211 views
17

我目前正在開發一個C#項目,該項目是一個控制檯應用程序,其中包含一個WCF soap服務。Mono中自行託管的WCF服務

下面是我用來打開主機的代碼。

var baseAddress = new Uri(Configuration.soapServerSettings.soapServerUrl); 
var host = new ServiceHost(typeof(SoapServer), baseAddress); 
BasicHttpBinding basicHttpBinding = new BasicHttpBinding(); 

var meta = new ServiceMetadataBehavior() 
{ 
    HttpGetEnabled = true, 
    HttpGetUrl = new Uri("", UriKind.Relative) 
}; 

host.Description.Behaviors.Add(meta); 

var debugBehaviour = new ServiceDebugBehavior() 
{ 
    HttpHelpPageEnabled = true, 
    HttpHelpPageUrl = new Uri("", UriKind.Relative), 
    IncludeExceptionDetailInFaults = true 
}; 

ServiceEndpoint endpnt = host.AddServiceEndpoint(
    typeof(ISoapInterface), 
    basicHttpBinding, 
    "EmailServer"); 

host.Description.Behaviors.Remove(typeof(ServiceDebugBehavior)); 
host.Description.Behaviors.Add(debugBehaviour); 
host.Open(); 

這是工作完全正常的Windows,但在Linux上,當我得到我瀏覽到它,我得到以下信息:

XmlSchema error: Named item http://schemas.microsoft.com/2003/10/Serialization/:anyType was already contained in the schema object table. Consider setting MONO_STRICT_MS_COMPLIANT to 'yes' to mimic MS implementation. Related schema item SourceUri: , Line 3, Position 3.

我不知道從哪裏開始尋找到這個問題。

感謝您的幫助,您可以提供

更新: 按照古德溫羅布建議,我已經添加了MONO_STRICT_MS_COMPLIANT作爲環境變量這似乎已經奏效,我可以訪問該服務。但是,我現在遇到了一個不同的問題。我有一個PHP頁面,每隔幾秒就會發出幾個請求,但一分鐘後,我的應用程序崩潰。

我得到以下異常:

This XmlWriter does not accept StartTag at this state Error. at System.Xml.XmlTextWriter.WriteStartElement (System.String prefix, System.String localName, System.String namespaceUri) [0x00000] in :0 at System.Xml.DefaultXmlWriter.WriteStartElement (System.String prefix, System.String localName, System.String ns) [0x00000] in :0 at System.Xml.XmlWriter.WriteStartElement (System.String localName, System.String ns) [0x00000] in :0 at System.ServiceModel.Logger.TraceCore (TraceEventType eventType, Int32 id, Boolean hasRelatedActivity, Guid relatedActivity, System.Object[] data) [0x00000] in :0 at System.ServiceModel.Logger.LogMessage (System.ServiceModel.Diagnostics.MessageLogTraceRecord log) [0x00000] in :0 at System.ServiceModel.Logger.LogMessage (MessageLogSourceKind sourceKind, System.ServiceModel.Channels.Message& msg, Int64 maxMessageSize) [0x00000] in :0 at System.ServiceModel.Channels.Http.HttpRequestContext.InternalReply (System.ServiceModel.Channels.Message msg, TimeSpan timeout) [0x00000] in :0 at System.ServiceModel.Channels.Http.HttpRequestContext.Reply (System.ServiceModel.Channels.Message msg, TimeSpan timeout) [0x00000] in :0 at System.ServiceModel.Dispatcher.MessageProcessingContext.Reply (Boolean useTimeout) [0x00000] in :0 at System.ServiceModel.Dispatcher.OperationInvokerHandler.Reply (System.ServiceModel.Dispatcher.MessageProcessingContext mrc, Boolean useTimeout) [0x00000] in :0 at System.ServiceModel.Dispatcher.OperationInvokerHandler.ProcessRequest (System.ServiceModel.Dispatcher.MessageProcessingContext mrc) [0x00000] in :0 at System.ServiceModel.Dispatcher.BaseRequestProcessorHandler.ProcessRequestChain (System.ServiceModel.Dispatcher.MessageProcessingContext mrc) [0x00000] in :0 at System.ServiceModel.Dispatcher.BaseRequestProcessorHandler.ProcessRequestChain (System.ServiceModel.Dispatcher.MessageProcessingContext mrc) [0x00000] in :0 at System.ServiceModel.Dispatcher.HandlersChain.ProcessRequestChain (System.ServiceModel.Dispatcher.MessageProcessingContext mrc) [0x00000] in :0 at System.ServiceModel.Dispatcher.BaseRequestProcessor.ProcessRequest (System.ServiceModel.Dispatcher.MessageProcessingContext mrc) [0x00000] in :0

Unhandled Exception: System.InvalidOperationException: This XmlWriter does not accept StartTag at this state Error. at System.Xml.XmlTextWriter.WriteStartElement (System.String prefix, System.String localName, System.String namespaceUri) [0x00000] in :0 at System.Xml.DefaultXmlWriter.WriteStartElement (System.String prefix, System.String localName, System.String ns) [0x00000] in :0 at System.Xml.XmlWriter.WriteStartElement (System.String localName, System.String ns) [0x00000] in :0 at System.ServiceModel.Logger.TraceCore (TraceEventType eventType, Int32 id, Boolean hasRelatedActivity, Guid relatedActivity, System.Object[] data) [0x00000] in :0 at System.ServiceModel.Logger.Log (TraceEventType eventType, System.String message, System.Object[] args) [0x00000] in :0 at System.ServiceModel.Logger.Error (System.String message, System.Object[] args) [0x00000] in :0 at System.ServiceModel.Dispatcher.ListenerLoopManager.ProcessErrorWithHandlers (IChannel ch, System.Exception ex, System.ServiceModel.Channels.Message& res) [0x00000] in :0 at System.ServiceModel.Dispatcher.ListenerLoopManager.ProcessRequest (IReplyChannel reply, System.ServiceModel.Channels.RequestContext rc) [0x00000] in :0 at System.ServiceModel.Dispatcher.ListenerLoopManager.TryReceiveRequestDone (IAsyncResult result) [0x00000] in :0

我也似乎不能夠訪問通過VS2010 WCF測試客戶端的服務,它並沒有錯誤,它只是與進度條坐在那裏50%,並沒有得到任何進一步的。

在Apache的錯誤日誌中我得到以下錯誤:

System.ArgumentException: Should be something like [[hostname:]port:]VPath:realpath at Mono.WebServer.ApplicationServer.AddApplicationsFromCommandLine (System.String applications) [0x00000] in :0 at (wrapper remoting-invoke-with-check) Mono.WebServer.ApplicationServer:AddApplicationsFromCommandLine (string) at Mono.WebServer.Apache.Server.RealMain (System.String[] args, Boolean root, IApplicationHost ext_apphost, Boolean quiet) [0x00000] in :0 at (wrapper remoting-invoke-with-check) Mono.WebServer.Apache.Server:RealMain (string[],bool,Mono.WebServer.IApplicationHost,bool) at Mono.WebServer.Apache.Server.Main (System.String[] args) [0x00000] in :0 [ERROR] FATAL UNHANDLED EXCEPTION: System.ArgumentException: Should be something like [[hostname:]port:]VPath:realpath at Mono.WebServer.ApplicationServer.AddApplicationsFromCommandLine (System.String applications) [0x00000] in :0 at (wrapper remoting-invoke-with-check) Mono.WebServer.ApplicationServer:AddApplicationsFromCommandLine (string) at Mono.WebServer.Apache.Server.RealMain (System.String[] args, Boolean root, IApplicationHost ext_apphost, Boolean quiet) [0x00000] in :0 at (wrapper remoting-invoke-with-check) Mono.WebServer.Apache.Server:RealMain (string[],bool,Mono.WebServer.IApplicationHost,bool) at Mono.WebServer.Apache.Server.Main (System.String[] args) [0x00000] in :0

更新2: 我似乎有這樣的工作,現在除了我只能在本地訪問該服務。即Web服務可以在本地訪問,並且功能可以完成他們應該做的事情,但是我無法從另一臺PC訪問它。即我試圖訪問使用WCF測試客戶端從dev的PC我的開發PC的單服務器上的WCF服務,然後我得到以下輸出:

Error: Cannot obtain Metadata from http://192.168.1.74:6525/ If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error URI: http://192.168.1.74:6525/ Metadata contains a reference that cannot be resolved: 'http://192.168.1.74:6525/ '.
Content Type application/soap+xml; charset=utf-8 was not supported by service http://192.168.1.74:6525/ . The client and service bindings may be mismatched. The remote server returned an error: (415) Expected content-type 'text/xml; charset=utf-8' but got 'application/soap+xml; charset=utf-8'.HTTP GET Error URI: http://192.168.1.74:6525/ The document was understood, but it could not be processed. - The WSDL document contains links that could not be resolved. - There was an error downloading ' http://localhost:6525/?xsd=xsd0 '. - Unable to connect to the remote server - No connection could be made because the target machine actively refused it 127.0.0.1:6525.

更新3: 經進一步測試它看起來好像是一次接通很多電話的時候。在瀏覽器頁面上不停地刷新使用該服務似乎會使其崩潰。

它看起來好像在單聲道內的System.ServiceModel.Logger.TraceCore有什麼問題。有沒有辦法禁用這部分單聲道,所以我不受這個問題的影響。

+0

您是否嘗試過使用錯誤消息中的建議,將MONO_STRICT_MS_COMPLIANT設置爲yes?檢查此博客帖子http://erictummers.wordpress.com/2012/01/24/wsdl-in-mono/ – vittore 2013-03-11 19:15:45

+0

我一直無法找到這是設置在哪裏 – Boardy 2013-03-11 19:16:46

+2

我相信這是一個環境變量 – 2013-03-11 19:18:50

回答

1

看來有可能是我從託管服務器的一些權限相關的問題,請檢查一次給予特定端口的權限。希望這可能有用。

+0

其他客戶端能夠連接到它,例如vs2010中的WCF測試客戶端 – Boardy 2013-08-08 08:30:25