1

NetTcpBinding を使用する WCF サービスがあり、それを WPF アプリケーションでホストしたいと考えています。サービスは正しく開始されているようですが、ビジュアル スタジオで「サービス参照の追加」を使用してメタデータを取得しようとすると、次の例外が発生します。

The URI prefix is not recognized.
Metadata contains a reference that cannot be resolved: 'net.tcp://localhost:8000/Mandrake/mex'.

私のサービス プロジェクトの App.config ファイル:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

<appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
  <compilation debug="true" />
</system.web>
<system.serviceModel>
  <services>
    <service name="Mandrake.Service.OTAwareService">
      <endpoint address="OTService" binding="netTcpBinding" contract="Mandrake.Service.IOTAwareService">
        <identity>
          <dns value="localhost" />
        </identity>
      </endpoint>
      <endpoint name="MEX" address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
      <host>
        <baseAddresses>
          <add baseAddress="net.tcp://localhost:8000/Mandrake/" />
        </baseAddresses>
      </host>
    </service>
  </services>
  <behaviors>
    <serviceBehaviors>
      <behavior>
        <serviceMetadata/>
        <serviceDebug includeExceptionDetailInFaults="False" />
      </behavior>
    </serviceBehaviors>
  </behaviors>
</system.serviceModel>

</configuration>

ホスティング アプリケーションのコード:

Uri baseAddress = new Uri("net.tcp://localhost:8000/Mandrake");
ServiceHost host = new ServiceHost(typeof(OTAwareService), baseAddress);

try
{
    host.AddServiceEndpoint(typeof(IOTAwareService), new NetTcpBinding(), "OTService");

}
catch (CommunicationException e)
{
    Console.WriteLine(e.Message);
    host.Abort();
}

この問題に対して私が見つけた解決策は、主に「serviceMetaData」をサービス構成に追加するか、mex エンドポイントを提供することでした。何か提案していただけますか?

編集:

最終設定:

<system.serviceModel>
<behaviors>
  <serviceBehaviors>
    <behavior name="NewBehavior0">
      <serviceMetadata />
      <serviceDebug includeExceptionDetailInFaults="True" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<services>
  <service name="Mandrake.Service.OTAwareService" behaviorConfiguration="NewBehavior0">
    <host>
      <baseAddresses>
        <add baseAddress="net.tcp://localhost:8036/OTService"/>
      </baseAddresses>
    </host>

    <endpoint address="" binding="netTcpBinding" name="TcpEndpoint" contract="Mandrake.Service.IOTAwareService" />
    <endpoint address="mex" binding="mexTcpBinding" name="MetadataEndpoint" contract="IMetadataExchange" />

  </service>
</services>
</system.serviceModel>

ホスティング アプリケーション:

host = new ServiceHost(typeof(OTAwareService));
host.Open();
4

1 に答える 1

2

serviceDebug の includeExceptionDetailInFaults を有効にすると、かなり明確になりました。

Mandrake.Service.IOTCallback.Send operation references a message element [http://tempuri.org/:Send] that has already been exported from the Mandrake.Service.IOTAwareService.Send operation

そのため、サービス コントラクトとコールバック インターフェイスにも Send(OTMessage) 操作がありました。かなり醜い間違いですが、誰かに役立つ場合に備えて、ここに解決策を残しておくと思いました。

于 2014-05-01T21:53:32.327 に答える