1

net.tcp を使用して WCF を Windows サービスとしてホストしています。サービスの開始時にWindowsサービスをインストールした後、サービスが開始および停止されたことがわかります。

サービス 'MYService' にエンドポイントを追加するには、空でないコントラクト名を指定する必要があります。System.ServiceModel.Description.ConfigLoader.LookupContract (文字列の契約名、文字列のサービス名) で

私の OnStart 関数は次のとおりです

 protected override void OnStart(string[] args)
        {
            try
            {
                if (myServiceHost != null)
                {
                    myServiceHost.Close();
                }
                myServiceHost = new ServiceHost(typeof(MYservice));
                myServiceHost.Open();

            }
            catch (Exception ex)
            {
                log.Error("ONStart", ex);
                throw;
            }

        }

構成ファイルは次のとおりです。

<serviceHostingEnvironment minFreeMemoryPercentageToActivateService="10" />
<services>
  <service behaviorConfiguration="myServiceBehavior"
    name="myNamespace.myTestService">
    <endpoint binding="netTcpBinding" bindingConfiguration="netTCPBindingConfig" contract="myNamespace.ServiceInterface.ImyTestService" />
    <endpoint binding="mexTcpBinding" bindingConfiguration="" />
    <host>
      <baseAddresses>
        <add baseAddress="net.tcp://10.1.3.69:8523/TestService" />
      </baseAddresses>
      <timeouts closeTimeout="10:00:10" openTimeout="10:01:00" />
    </host>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="myServiceBehavior">
      <serviceMetadata httpGetEnabled="false" httpsGetEnabled="false" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
  </serviceBehaviors>
</behaviors>

4

2 に答える 2

5

構成ファイルには、次のものがあります。

<endpoint binding="netTcpBinding" bindingConfiguration="netTCPBindingConfig" contract="myNamespace.ServiceInterface.ISomeService" /> `

の代わりにISomeService、によって実装されるインターフェースを指定する必要がありますMYService

編集

さらに、mexバインディングには、指定されたコントラクトが必要です。contract="IMetadataExchange"

もう一度編集

あなたの便宜のために、これはあなたのmexバインディングがどのように見えるべきかです:

<endpoint binding="mexTcpBinding" address="mex" bindingConfiguration="" contract="IMetadataExchange" />
于 2012-04-25T09:52:34.673 に答える
-2

これを試してください:

        protected override void OnStart(string[] args)
        {
            try
            {
                myServiceHost = new ServiceHost(typeof(MYservice));
                myServiceHost.Open();
                Console.ReadKey();
            }
            catch (Exception ex)
            {
                log.Error("ONStart", ex); throw;
            }
            finally
            {
                myServiceHost.Close();

            }
        }
于 2012-04-25T09:43:00.233 に答える