14

インターフェイスをサンプルクライアントプロジェクトにコピーしてテストしたWCFサービスがあります。
ここで、サービス参照を追加して適切に機能させたいと思います。
このサービスは、(を使用して)ホスティングしているWindowsでホストされていますinstallUtil
このサービスには、外部(インターフェース+データコントラクト)と内部(実装)の2つのプロジェクトがあります。
何らかの理由でapp.configがなかったので、手動で追加しました。

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <services>
      <service name="ExecutionService" behaviorConfiguration="Default">
        <endpoint name="TCPEndpoint" address="" binding ="netTcpBinding" contract="Externals.IExecutionService"/>
        <host>
          <baseAddresses>
            <add baseAddress="net.tcp://localhost:3040/ExecutionService"/>
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="Default">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

サンプルクライアントからサービス参照を追加しようとすると、次のエラーが発生します。

Metadata contains a reference that cannot be resolved: 'net.tcp://localhost:3040/ExecutionService/Externals.IExecutionService'.
There was no endpoint listening at net.tcp://localhost:3040/ExecutionService/Externals.IExecutionService that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
If the service is defined in the current solution, try building the solution and adding the service reference again.

ここで、 app.configに必要がないことがわかりました。
私は少し混乱していて、の初心者ですWCF。素敵なアプリ
はどのように私のサービスを参照できますか?WPFサービスをWindowsでホストしたいのですが、dllを一緒にドラッグしたくありません。

編集
メタデータエンドポイントを追加すると、appconfigは次のようになります。

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <services>
      <service name="ExecutionService" behaviorConfiguration="Default">
        <endpoint name="TCPEndpoint" 
                  address="" 
                  binding ="netTcpBinding" 
                  contract="Externals.IExecutionService"/>
        <endpoint address="mex" 
                  binding="maxHttpBinding" 
                  contract="Externals.IExecutionService"/>
        <host>
          <baseAddresses>
            <add baseAddress="net.tcp://localhost:3040/ExecutionService"/>
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="Default">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

net.tcp://localhost:3040/ExecutionServiceを使用してサービス参照を追加しようとしましたnet.tcp://localhost:3040/ExecutionService/Externalsnet.tcp://localhost:3040/ExecutionService/Externals/IExecutionService、それでも同じエラーが発生します。

4

3 に答える 3

30

あなたがする必要があります:

  1. maxHttpBinding-> mexTcpBinding-net.tcpエンドポイントでmexHttpBindingを使用することはできません(そしてそれはmaxではなくmexです)
  2. mexエンドポイントのコントラクトはIMetadataExchangeである必要があります-このエンドポイントを介してサービスメタデータを利用できるようにするため
  3. httpGetEnabled = "false"メタデータを取得するhttpエンドポイントがないため、
  4. 単純なコンソールホストでソリューションをテストしていたとき、<service>タグの名前をExternals.ExecutionServiceに変更する必要がありました(ただし、これはサービスのインスタンス化方法によって異なります)

次に、サービス参照は次の場所で利用可能になります。net.tcp://localhost:3040/ExecutionService/mex ベースアドレスはnet.tcp://localhost:3040/ExecutionServiceであり、mexエンドポイントの相対アドレスは次のように設定されます。mex

最終的なapp.configは以下のとおりです。

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
  <service name="Externals.ExecutionService" behaviorConfiguration="Default">
    <endpoint name="TCPEndpoint"
              address=""
              binding ="netTcpBinding"
              contract="Externals.IExecutionService"/>
    <endpoint address="mex"
              binding="mexTcpBinding"
              contract="IMetadataExchange"/>
    <host>
      <baseAddresses>
        <add baseAddress="net.tcp://localhost:3040/ExecutionService"/>
      </baseAddresses>
    </host>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="Default">
      <serviceMetadata httpGetEnabled="false" />
      <serviceDebug includeExceptionDetailInFaults="true"/>
    </behavior>
  </serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>

構成が正しいかどうかを簡単にテストするために、コンソールホストアプリをサービスホストとして使用しました。Program.cs:

using System;
using System.ServiceModel;

namespace Externals
{
    class Program
    {
        static void Main(string[] args)
        {

            var sh=new ServiceHost(typeof(ExecutionService));
            sh.Open();
            Console.WriteLine("Service running press any key to terminate...");
            Console.ReadKey();
            sh.Close();
        }
    }
}

コンソールアプリを実行し、を使用してプロジェクトにサービス参照を追加してみてくださいnet.tcp://localhost:3040/ExecutionService/mex

于 2013-03-15T00:27:34.580 に答える
2

これを変える:

<endpoint address="mex" 
                  binding="maxHttpBinding" 
                  contract="Externals.IExecutionService"/>

に:

<endpoint address="mex" 
                  binding="mexTcpBinding" 
                  contract="IMetadataExchange"/>

maxHttpBindingではなくmexTcpBindingであることに注意してください。ここにも、タイプミスがあります。

于 2013-03-18T10:50:22.273 に答える
2

一見、メタデータエンドポイントを忘れてしまいました

于 2013-03-07T13:39:25.250 に答える