我工作的一个C#WCF应用程序。我正尝试启动一个自助托管在控制台应用程序中的soap服务。WCF SOAP服务与元数据导出
我想要做的一切编程为将要在其中会有不同的值,如URL等其它各种应用中,将要使用的库。
我添加的代码,但是当我尝试启动,我得到一个错误的服务:
The contract name 'IMetadataExchange' could not be found i n the list of contracts implemented by the service Engine.SoapServer. Add a Ser viceMetadataBehavior to the configuration file or to the ServiceHost directly to enable support for this contract.
下面是如何我开始SOAP服务
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上工作
UPDATE 由于p呃Vibhu,建议,我试图做什么建议,现在我得到一个不同的错误,所以希望得到的地方,错误如下:
MessageVersion 'Soap11 (
http://schemas.xmlsoap.org/soap/envelope/
) AddressingNone (http://schemas.microsoft.com/ws/2005/05/addressing/none
)' is not supported in this scenario. Only MessageVersion 'EnvelopeNone (11http://s chemas.microsoft.com/ws/2005/05/envelope/none11) AddressingNone (http://schemas.microsoft.com/ws/2005/05/addressing/none
)' is supported.
更新2 我又做了什么vibhu建议和肥皂服务现在已经成功开始,但是当我尝试从VS2010捆绑的WCF Test客户端访问它时,我收到了一个关于不匹配的内容类型的错误。
下面是错误
> 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
谢谢,试过你的建议,但现在得到一个不同的错误。我已经在这两个服务行为的更新我的问题 – Boardy
注释掉HttpGetBinding,看看它是否工作 – vibhu
由于目前该服务正在启动,但试图访问时得到一个错误。当您从测试客户端添加服务引用我已经更新了问题 – Boardy