C# 无法调试wcf windows服务

C# 无法调试wcf windows服务,c#,wcf,C#,Wcf,我们的应用程序访问WCF服务,该服务由一台计算机上的Windows服务托管。客户端应用程序和服务始终位于同一台计算机上 <endpoint address="http://localhost/VssService/" binding="basicHttpBinding" bindingConfiguration="" contract="ClientSaver.VssService.IVssService" />

我们的应用程序访问WCF服务,该服务由一台计算机上的Windows服务托管。客户端应用程序和服务始终位于同一台计算机上

            <endpoint address="http://localhost/VssService/" binding="basicHttpBinding"
                bindingConfiguration="" contract="ClientSaver.VssService.IVssService" />                            
        </service>
    </services>

  <behaviors>
    <serviceBehaviors>
      <behavior name="VssServiceBehavior">
        <serviceMetadata httpGetEnabled="true" policyVersion="Policy15" />
        <serviceDebug includeExceptionDetailInFaults="true" />
      </behavior>
    </serviceBehaviors>
  </behaviors>      
</system.serviceModel>
我创建了一个承载WCF服务的Windows服务。为了测试我的Windows服务代码,我创建了一个控制台应用程序,其中包含与我的Windows服务相同的app.config和代码。我在一个调试线程中启动控制台应用程序,并在另一个调试线程中启动客户端。一切都很完美,我可以很容易地使用调试器

            <endpoint address="http://localhost/VssService/" binding="basicHttpBinding"
                bindingConfiguration="" contract="ClientSaver.VssService.IVssService" />                            
        </service>
    </services>

  <behaviors>
    <serviceBehaviors>
      <behavior name="VssServiceBehavior">
        <serviceMetadata httpGetEnabled="true" policyVersion="Policy15" />
        <serviceDebug includeExceptionDetailInFaults="true" />
      </behavior>
    </serviceBehaviors>
  </behaviors>      
</system.serviceModel>
现在的摩擦

            <endpoint address="http://localhost/VssService/" binding="basicHttpBinding"
                bindingConfiguration="" contract="ClientSaver.VssService.IVssService" />                            
        </service>
    </services>

  <behaviors>
    <serviceBehaviors>
      <behavior name="VssServiceBehavior">
        <serviceMetadata httpGetEnabled="true" policyVersion="Policy15" />
        <serviceDebug includeExceptionDetailInFaults="true" />
      </behavior>
    </serviceBehaviors>
  </behaviors>      
</system.serviceModel>
因此,我创建了一个安装程序并安装了我的Windows服务。成功启动后,我在VisualStudio2010中成功地将服务引用添加到我的客户端。我通过“附加到流程”成功附加到服务。我在调试线程中启动了我的客户端,但当我尝试单步执行远程方法时,我得到“无法自动单步执行服务器。调试器未能在服务器进程中停止”。这在[NetNamedPipeBinding_IVssService]和[BasicHttpBinding_IVssService]中都会发生。我已经为此挣扎了好几个小时,已经没有办法了,所以我希望你能帮助我。我已经包含了我的Windows服务和客户端应用程序的app.config文件。希望他们能帮忙

            <endpoint address="http://localhost/VssService/" binding="basicHttpBinding"
                bindingConfiguration="" contract="ClientSaver.VssService.IVssService" />                            
        </service>
    </services>

  <behaviors>
    <serviceBehaviors>
      <behavior name="VssServiceBehavior">
        <serviceMetadata httpGetEnabled="true" policyVersion="Policy15" />
        <serviceDebug includeExceptionDetailInFaults="true" />
      </behavior>
    </serviceBehaviors>
  </behaviors>      
</system.serviceModel>
我感谢您花时间阅读此问题,并希望您能帮助解决此问题

            <endpoint address="http://localhost/VssService/" binding="basicHttpBinding"
                bindingConfiguration="" contract="ClientSaver.VssService.IVssService" />                            
        </service>
    </services>

  <behaviors>
    <serviceBehaviors>
      <behavior name="VssServiceBehavior">
        <serviceMetadata httpGetEnabled="true" policyVersion="Policy15" />
        <serviceDebug includeExceptionDetailInFaults="true" />
      </behavior>
    </serviceBehaviors>
  </behaviors>      
</system.serviceModel>
迈克

            <endpoint address="http://localhost/VssService/" binding="basicHttpBinding"
                bindingConfiguration="" contract="ClientSaver.VssService.IVssService" />                            
        </service>
    </services>

  <behaviors>
    <serviceBehaviors>
      <behavior name="VssServiceBehavior">
        <serviceMetadata httpGetEnabled="true" policyVersion="Policy15" />
        <serviceDebug includeExceptionDetailInFaults="true" />
      </behavior>
    </serviceBehaviors>
  </behaviors>      
</system.serviceModel>
==================================服务APP.CONFIG=============================

            <endpoint address="http://localhost/VssService/" binding="basicHttpBinding"
                bindingConfiguration="" contract="ClientSaver.VssService.IVssService" />                            
        </service>
    </services>

  <behaviors>
    <serviceBehaviors>
      <behavior name="VssServiceBehavior">
        <serviceMetadata httpGetEnabled="true" policyVersion="Policy15" />
        <serviceDebug includeExceptionDetailInFaults="true" />
      </behavior>
    </serviceBehaviors>
  </behaviors>      
</system.serviceModel>

========================================客户端APP.CONFIG=============================

            <endpoint address="http://localhost/VssService/" binding="basicHttpBinding"
                bindingConfiguration="" contract="ClientSaver.VssService.IVssService" />                            
        </service>
    </services>

  <behaviors>
    <serviceBehaviors>
      <behavior name="VssServiceBehavior">
        <serviceMetadata httpGetEnabled="true" policyVersion="Policy15" />
        <serviceDebug includeExceptionDetailInFaults="true" />
      </behavior>
    </serviceBehaviors>
  </behaviors>      
</system.serviceModel>


您不能跨越可执行边界。您需要在服务器代码(即项目)中设置断点。然后从服务器的项目连接到正在运行的windows服务进程(此处请小心…您需要将最新的服务器项目作为windows服务运行)。然后,当您进入Windows窗体应用程序时,它将被服务器的断点捕获。

您应该使用internet explorer作为默认浏览器来调试您的服务…

查看Windows调试工具。这里有两个工具可用于调试windows服务。

确定。当VS调试停止工作时,我使用的一种方法是将
System.Diagnostics.Debugger.Break()
放在服务代码(例如构造函数或方法)中的一个常规位置。这会导致JIT调试器启动,并允许我使用任何VS实例连接到服务,此时代码已断开

            <endpoint address="http://localhost/VssService/" binding="basicHttpBinding"
                bindingConfiguration="" contract="ClientSaver.VssService.IVssService" />                            
        </service>
    </services>

  <behaviors>
    <serviceBehaviors>
      <behavior name="VssServiceBehavior">
        <serviceMetadata httpGetEnabled="true" policyVersion="Policy15" />
        <serviceDebug includeExceptionDetailInFaults="true" />
      </behavior>
    </serviceBehaviors>
  </behaviors>      
</system.serviceModel>

显然,您将其从非调试代码中删除。

您是否尝试手动加载调试符号?这曾经发生在我身上,这是因为VS没有加载符号。

看到了吗?要将其标记为答案,请单击其中一个答案左侧类似Tik(Nike的标记)的图标。请注意:您可以通过跟踪和事件记录完成大部分WCF初始开发。请检查以下链接:。请同时检查此线程:。您可能希望检查提供的答案中有一个链接。当您使用默认VS Host运行WCF时,您可以跨WCF中的可执行边界执行步骤,但可能他正试图从一个项目(Windows项目)跨入WCF服务到另一个项目(WCF服务项目),而他们可能不在同一解决方案中。。。这将是进入的问题…也有可能以IIS和其他方式调试托管服务,总之,在与其他项目相同的解决方案中创建服务没有问题,解决方案并不意味着任何特定的内容。大家好,非常感谢你们的所有想法。Ivan建议不要在Microsoft服务中使用我们的方法,而是在另一个调试线程中运行我们的应用程序时在其中设置一个断点。这一建议奏效了。:)
            <endpoint address="http://localhost/VssService/" binding="basicHttpBinding"
                bindingConfiguration="" contract="ClientSaver.VssService.IVssService" />                            
        </service>
    </services>

  <behaviors>
    <serviceBehaviors>
      <behavior name="VssServiceBehavior">
        <serviceMetadata httpGetEnabled="true" policyVersion="Policy15" />
        <serviceDebug includeExceptionDetailInFaults="true" />
      </behavior>
    </serviceBehaviors>
  </behaviors>      
</system.serviceModel>