2013-07-22 72 views
0

我工作的一個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 

回答

1

將您的元數據的行爲添加MEX終結前 -

var meta = new ServiceMetadataBehavior() 
{ 
    //ExternalMetadataLocation = new Uri(soapServerUrl + "/CritiMon?wsdl"), 
    HttpGetEnabled = true, 
    HttpGetUrl = new Uri("", UriKind.Relative), 
    HttpGetBinding = basicHttpBinding, 
}; 

host.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexHttpBinding(), "mex"); 
+0

謝謝,試過你的建議,但現在得到一個不同的錯誤。我已經在這兩個服務行爲的更新我的問題 – Boardy

+0

註釋掉HttpGetBinding,看看它是否工作 – vibhu

+0

由於目前該服務正在啓動,但試圖訪問時得到一個錯誤。當您從測試客戶端添加服務引用我已經更新了問題 – Boardy