17

我目前正在开发一个 C# 项目,它是一个控制台应用程序,其中托管了 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 错误:命名项目 http://schemas.microsoft.com/2003/10/Serialization/:anyType已包含在架构对象表中。考虑将 MONO_STRICT_MS_COMPLIANT 设置为“是”以模仿 MS 实现。相关架构项 SourceUri: , Line 3, Position 3。

我不知道从哪里开始研究这个问题。

感谢您的任何帮助,您可以提供

更新: 根据 Rob Goodwins 的建议,我添加了MONO_STRICT_MS_COMPLIANT环境变量,这似乎确实有效,我可以访问该服务。但是,我现在遇到了一个不同的问题。我有一个 PHP 页面,它每隔几秒钟执行几个请求,但一分钟后,我的应用程序崩溃了。

我得到以下异常:

此 XmlWriter 在此状态下不接受 StartTag 错误。在 System.Xml.XmlTextWriter.WriteStartElement(System.String 前缀,System.String localName,System.String namespaceUri)[0x00000] 在:0 在 System.Xml.DefaultXmlWriter.WriteStartElement(System.String 前缀,System.String localName,System .String ns) [0x00000] in :0 在 System.Xml.XmlWriter.WriteStartElement (System.String localName, System.String ns) [0x00000] in :0 在 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.

未处理的异常:System.InvalidOperationException:此 XmlWriter 在此状态下不接受 StartTag 错误。在 System.Xml.XmlTextWriter.WriteStartElement(System.String 前缀,System.String localName,System.String namespaceUri)[0x00000] 在:0 在 System.Xml.DefaultXmlWriter.WriteStartElement(System.String 前缀,System.String localName,System .String ns) [0x00000] in :0 在 System.Xml.XmlWriter.WriteStartElement (System.String localName, System.String ns) [0x00000] in :0 在 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(系统。

我似乎也无法通过 VS2010 WCF 测试客户端访问该服务,它不会出错,它只是坐在那里,进度条为 50%,并且没有任何进展。

在 apache 错误日志中,我收到以下错误:

System.ArgumentException: 应该类似于 [[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.Main (System.String[] args) [0x00000] 中的 Mono.WebServer.Apache.Server.Main (System.String[] args) 处的 Mono.WebServer.Apache.Server:RealMain (string[],bool,Mono.WebServer.IApplicationHost,bool) :0 [错误] 致命的未处理异常:System.ArgumentException:应该类似于 Mono.WebServer.ApplicationServer 的 [[hostname:]port:]VPath:realpath。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) 在 Mono.WebServer.Apache.Server.Main (System.String[] args) [0x00000] in :0IApplicationHost ext_apphost, Boolean quiet) [0x00000] in :0 at (wrapper remoting-invoke-with-check) Mono.WebServer.Apache.Server:RealMain (string[],bool,Mono.WebServer.IApplicationHost,bool) 在 Mono。 WebServer.Apache.Server.Main (System.String[] args) [0x00000] in :0IApplicationHost ext_apphost, Boolean quiet) [0x00000] in :0 at (wrapper remoting-invoke-with-check) Mono.WebServer.Apache.Server:RealMain (string[],bool,Mono.WebServer.IApplicationHost,bool) 在 Mono。 WebServer.Apache.Server.Main (System.String[] args) [0x00000] in :0

更新 2: 我现在似乎可以正常工作了,只是我只能在本地访问该服务。即,可以在本地访问 Web 服务,并且功能可以执行应有的操作,但我无法从另一台 PC 访问它。即我正在尝试使用来自开发 PC 的开发 PC 的 WCF 测试客户端访问 Mono 服务器上的 WCF 服务,然后我得到以下输出:

错误:无法从中获取元数据http://192.168.1.74:6525/如果这是您有权访问的 Windows (R) Communication Foundation 服务,请检查您是否已在指定地址启用元数据发布。有关启用元数据发布的帮助,请参阅位于 http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange 错误 URI 的 MSDN 文档:http://192.168.1.74:6525/ 元数据包含无法解析的引用:'http://192.168.1.74:6525/'。
内容类型应用程序/soap+xml;charset=utf-8 不受 service 支持http://192.168.1.74:6525/。客户端和服务绑定可能不匹配。远程服务器返回错误:(415) Expected content-type 'text/xml; charset=utf-8' 但得到 'application/soap+xml; charset=utf-8'.HTTP GET 错误 URI: http://192.168.1.74:6525/ 该文件已被理解,但无法处理。- WSDL 文档包含无法解析的链接。- 下载“ ”时出错http://localhost:6525/?xsd=xsd0。- 无法连接到远程服务器 - 无法建立连接,因为目标机器主动拒绝了它 127.0.0.1:6525。

更新 3: 经过进一步测试,看起来好像一次对服务进行了多次调用。在使用该服务的浏览器页面上不断刷新似乎会使它崩溃。

看起来好像System.ServiceModel.Logger.TraceCoreMono 内部有问题。有没有办法禁用这部分单声道,这样我就不会受到这个问题的影响。

4

1 回答 1

1

似乎托管服务器可能存在一些与权限相关的问题,请检查一次授予特定端口的权限。希望这可能有用。

于 2013-08-07T23:07:45.647 回答