我正在开发一个 C# WCF 应用程序。我正在尝试启动一个在控制台应用程序中自托管的肥皂服务。
我想以编程方式做所有事情,因为它将在一个库中,该库将具有不同的值,例如 URL 等,用于将要使用的各种其他应用程序。
我已经添加了代码,但是当我尝试启动服务时出现错误:
在服务 Engine.SoapServer 实施的合同列表中找不到合同名称“IMetadataExchange”。将 ServiceMetadataBehavior 添加到配置文件或直接添加到 ServiceHost 以启用对此协定的支持。
以下是我开始肥皂服务的方式
if (Environment.GetEnvironmentVariable("MONO_STRICT_MS_COMPLIANT") != "yes")
{
Environment.SetEnvironmentVariable("MONO_STRICT_MS_COMPLIANT", "yes");
}
if (String.IsNullOrEmpty(soapServerUrl))
{
string message = "Not starting Soap Server: URL or Port number is not set in config file";
library.logging(methodInfo, message);
library.setAlarm(message, CommonTasks.AlarmStatus.Medium, methodInfo);
return;
}
baseAddress = new Uri(soapServerUrl);
host = new ServiceHost(soapHandlerType, baseAddress);
BasicHttpBinding basicHttpBinding = new BasicHttpBinding();
//basicHttpBinding.Namespace = "http://tempuri.org/";
host.AddServiceEndpoint(soapManagerInterface, basicHttpBinding, soapServerUrl);
host.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexHttpBinding(), "mex");
var meta = new ServiceMetadataBehavior()
{
//ExternalMetadataLocation = new Uri(soapServerUrl + "/CritiMon?wsdl"),
HttpGetEnabled = true,
HttpGetUrl = new Uri("", UriKind.Relative),
HttpGetBinding = basicHttpBinding,
};
//meta.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
host.Description.Behaviors.Add(meta);
var debugBehaviour = new ServiceDebugBehavior()
{
HttpHelpPageEnabled = true,
HttpHelpPageUrl = new Uri("", UriKind.Relative),
IncludeExceptionDetailInFaults = true,
HttpHelpPageBinding = basicHttpBinding,
};
host.Description.Behaviors.Remove(typeof(ServiceDebugBehavior));
host.Description.Behaviors.Add(debugBehaviour);
host.Opened += new EventHandler(host_Opened);
host.Faulted += new EventHandler(host_Faulted);
host.Closed += new EventHandler(host_Closed);
host.UnknownMessageReceived += new EventHandler<UnknownMessageReceivedEventArgs>(host_UnknownMessageReceived);
host.Open();
目前我在 Windows 上看到了这个问题,但我也需要它在 Mono 下的 Linux 上工作
更新 根据 Vibhu 的建议,我已经尝试按照建议进行操作,但现在出现了不同的错误,因此希望能到达某个地方,错误如下:
此方案不支持MessageVersion 'Soap11 (
http://schemas.xmlsoap.org/soap/envelope/
) AddressingNone ( )'。http://schemas.microsoft.com/ws/2005/05/addressing/none
仅支持 MessageVersion 'EnvelopeNone (11http://s chemas.microsoft.com/ws/2005/05/envelope/none11) AddressingNone (http://schemas.microsoft.com/ws/2005/05/addressing/none
)'。
更新 2 我再次完成了 vibhu 建议的操作,soap 服务现在已成功启动,但是当我尝试从与 VS2010 捆绑的 WCF 测试客户端访问它时,我收到有关内容类型不匹配的错误。
下面是错误
> Error: Cannot obtain Metadata from http://localhost:8000/CritiMon 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://localhost:8000/CritiMon Metadata contains a
> reference that cannot be resolved: 'http://localhost:8000/CritiMon'.
> Content Type application/soap+xml; charset=utf-8 was not supported by
> service http://localhost:8000/CritiMon. The client and service
> bindings may be mismatched. The remote server returned an error:
> (415) Cannot process the message because the content type
> 'application/soap+xml; charset=utf-8' was not the expected type
> 'text/xml; charset=utf-8'..HTTP GET Error URI:
> http://localhost:8000/CritiMon There was an error downloading
> 'http://localhost:8000/CritiMon'. The request failed with HTTP
> status 400: Bad Request