gpt4 book ai didi

c# - Mono 中的自托管 WCF 服务

转载 作者:行者123 更新时间:2023-12-01 17:33:27 26 4
gpt4 key购买 nike

我目前正在开发一个 C# 项目,该项目是一个控制台应用程序,其中托管了 WCF Soap 服务。

下面是我用来打开主机的代码。

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.

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

感谢您提供的任何帮助

更新:根据 Rob Goodwins 的建议,我添加了 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:我现在似乎可以正常工作,除了我只能在本地访问该服务。 IE。网络服务可以在本地访问,并且功能可以完成它们应该做的事情,但我无法从另一台电脑访问它。 IE。我尝试使用开发 PC 上的 WCF 测试客户端从开发 PC 访问 Mono 服务器上的 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:经过进一步测试,看起来好像是一次性对该服务进行了多次调用。使用该服务不断地在浏览器页面上刷新似乎会使其崩溃。

Mono 中的 System.ServiceModel.Logger.TraceCore 似乎有问题。有没有办法禁用单声道的这一部分,这样我就不会受到这个问题的影响。

最佳答案

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

关于c# - Mono 中的自托管 WCF 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15346654/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com