簡體   English   中英

使用Windows Service的WCF托管,客戶端無法看到終結點

[英]WCF hosting with windows Service, client cannot see endpoint

我正在嘗試構建一個測試應用程序以測試wcf並了解更多信息:

我編寫了WCF服務,並將其托管在Windows服務中。 這是Windows服務中的我的app.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>    
     <services>
        <service name="WCFLibrary.CalculatorService"
                 behaviorConfiguration="CalculatorServiceBehavior">
           <host>
              <baseAddresses>
                 <add baseAddress="http://localhost:8000/ServiceModelSamples/service"/>
              </baseAddresses>
           </host>
           <!-- this endpoint is exposed at the base address provided by host: http://localhost:8000/ServiceModelSamples/service  -->
           <endpoint 
               address=""
               binding="wsHttpBinding"
               contract="WCFLibrary.ICalculator" />
           <!-- the mex endpoint is exposed at http://localhost:8000/ServiceModelSamples/service/mex -->
           <endpoint 
               address="mex"
               binding="mexHttpBinding"
               contract="IMetadataExchange" />
         </service>
      </services>
      <behaviors>
         <serviceBehaviors>
            <behavior name="CalculatorServiceBehavior">
               <serviceMetadata httpGetEnabled="true"/>
               <serviceDebug includeExceptionDetailInFaults="False"/>
            </behavior>
         </serviceBehaviors>
      </behaviors>
   </system.serviceModel>
</configuration>

現在,我想構建一個客戶端應用程序以使用WCF服務。 但是,當我轉到“ Add Service Reference它給了我一個錯誤,它無法到達端點。 我可以從服務管理器看到服務正在運行。 我通過從VS進行調試進行了測試。 在調試期間,客戶端可以看到端點。 但是,如果我停止調試並返回到服務管理器,則客戶端將看不到端點。

有什么事嗎 有什么線索嗎?

編輯1

Windows服務Service1.cs

namespace WindowsService
{
   public partial class Service1 : ServiceBase
   {
        public ServiceHost serviceHost = null;

        public Service1()
        {
             InitializeComponent();
        }

        public void onDebug()
        {
            OnStart(null);
        }

        protected override void OnStart(string[] args)
        {
            if (serviceHost != null)
            {
                serviceHost.Close();
            }

            // Create a ServiceHost for the CalculatorService type and 
            // provide the base address.
            serviceHost = new ServiceHost(typeof(CalculatorService));

            // Open the ServiceHostBase to create listeners and start 
            // listening for messages.
            serviceHost.Open();
        }

        protected override void OnStop()
        {
            if (serviceHost != null)
            {
                 serviceHost.Close();
                 serviceHost = null;
            }
        }
    }
}

Program.cs

namespace WindowsService
{
    public  class CalculatorWindowsService :ServiceBase
    {
        public ServiceHost serviceHost = null;

        public CalculatorWindowsService()
        {
            // Name the Windows Service
            ServiceName = "WCFWindowsServiceSample";
        }

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        public static void Main()
        {
//#if DEBUG
//           Service1 myservice = new Service1();
//           myservice.onDebug();
//           System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
//#else
            //  CalculatorWindowsService calc = new CalculatorWindowsService();
            ServiceBase.Run(new CalculatorWindowsService());
//#endif
        }
    }
}

上面的代碼沒有錯。 相同的代碼正在第二台筆記本電腦上工作。 因此,與第一台筆記本電腦上的OS或IE有關。 會檢查出來的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM