2012-04-04 12 views

答えて

2
  1. ランVS
  2. デバッグ]メニューから[プロセスにアタッチを選択...
  3. 検討し、また、あなたのサービスで
+0

あなたはサービスを開発している間に1日100回、あなたは半日の再インストールを無駄にします。 – TomTom

+0

魅力のように動作します:) – FrenkyB

7

をブレークポイントを置いて

  • あなたのサービスプロセスを選択します。開発中にWindows SERVICEでホスティングしないでください。サービスがあるときはいつでも、コマンドラインプログラム(/対話型のコマンドラインパラメータなどを含む)で起動するための別のコードパスがありますので、サービスデバッグの詳細を扱うことはできませんアセンブリの交換など)。

    私はデプロイメントなどのために "サービス"に切り替えます。デバッグは常に非サービスモードで行われます。

  • +0

    +1。私はいつもそれをする! – Aliostad

    +1

    +1。私のサービスコードはすべてサービスクラスに入っています。サービスクラスは、コンソールアプリケーションから実行して、うまくデバッグできます。 –

    +0

    実際に私は特別なラッパーを持っていますが、サービスクラスを使用し、サービスを「手動で」開始します。 ;)しかし、コンセプトは同じです。サービスとしてのサービスのデバッグはPAINです。 – TomTom

    0

    私はウォークスルーを見つけましたhere。 はService1のクラスは、このようになるので、OnDebugMode_Start及びOnDebugMode_Stopサービス(実際OnStartメソッドとOnStop保護方法を露出)に2つのメソッドを追加することを示唆している:

    public partial class Service1 : ServiceBase 
    { 
        ServiceHost _host; 
        public Service1() 
        { 
         InitializeComponent(); 
        } 
    
        protected override void OnStart(string[] args) 
        { 
         Type serviceType = typeof(MyWcfService.Service1); 
         _host = new ServiceHost(serviceType); 
         _host.Open(); 
        } 
    
        protected override void OnStop() 
        { 
         _host.Close(); 
        } 
    
        public void OnDebugMode_Start() 
        { 
         OnStart(null); 
        } 
    
        public void OnDebugMode_Stop() 
        { 
         OnStop(); 
        } 
    } 
    

    をし、このようなプログラムで起動:

    static void Main() 
    { 
        try 
        { 
    #if DEBUG 
         // Run as interactive exe in debug mode to allow easy debugging. 
    
         var service = new Service1(); 
         service.OnDebugMode_Start(); 
         // Sleep the main thread indefinitely while the service code runs in OnStart() 
         System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite); 
         service.OnDebugMode_Stop(); 
    #else 
         ServiceBase[] ServicesToRun; 
         ServicesToRun = new ServiceBase[] 
              { 
                new Service1() 
              }; 
         ServiceBase.Run(ServicesToRun); 
    #endif 
        } 
        catch (Exception ex) 
        { 
         throw ex; 
        } 
    } 
    

    のapp.configで設定サービス:

    <configuration> 
    <system.serviceModel> 
    <services> 
        <service name="MyWcfService.Service1"> 
        <endpoint address="" binding="basicHttpBinding" bindingConfiguration="" 
         contract="MyWcfService.IService1"> 
         <identity> 
         <dns value="localhost" /> 
         </identity> 
        </endpoint> 
        <endpoint address="mex" binding="mexHttpBinding" bindingConfiguration="" 
         contract="IMetadataExchange" /> 
        <host> 
         <baseAddresses> 
         <add baseAddress="http://localhost:8732/Design_Time_Addresses/MyWcfService/Service1/" /> 
         </baseAddresses> 
        </host> 
        </service> 
    </services> 
    <behaviors> 
        <serviceBehaviors> 
        <behavior> 
         <serviceMetadata httpGetEnabled="True" policyVersion="Policy15"/> 
         <serviceDebug includeExceptionDetailInFaults="True" /> 
        </behavior> 
        </serviceBehaviors> 
    </behaviors> 
    

    あなたはすべて設定されています。

    関連する問題