2013-03-11 214 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