0

私は C# WCF アプリケーションに取り組んでいます。コンソール アプリケーション内で自己ホストされる SOAP サービスを開始しようとしています。

使用される他のさまざまなアプリケーションの 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
4

1 に答える 1

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");
于 2013-07-23T11:17:31.213 に答える