Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在使用ASP.NET并排托管WCF时调试服务_C#_Asp.net_.net_Wcf_Iis 10 - Fatal编程技术网

C# 如何在使用ASP.NET并排托管WCF时调试服务

C# 如何在使用ASP.NET并排托管WCF时调试服务,c#,asp.net,.net,wcf,iis-10,C#,Asp.net,.net,Wcf,Iis 10,我有一个简单的托管WCF服务与ASP.NET并排,并且很难调试/介入该服务。下面是文件。提前谢谢 Web.config <system.web> <compilation debug="true" targetFramework="4.5.2"/> <httpRuntime targetFramework="4.5.2"/> </system.web> <system.serviceModel> &

我有一个简单的托管WCF服务与ASP.NET并排,并且很难调试/介入该服务。下面是文件。提前谢谢

Web.config

  <system.web>
    <compilation debug="true" targetFramework="4.5.2"/>
    <httpRuntime targetFramework="4.5.2"/>
  </system.web>

  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="mexBehavior">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>

    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />

    <services>
      <service name="WCF_TestService.TestService" behaviorConfiguration="mexBehavior">
        <endpoint address="" binding="basicHttpBinding" contract="WCF_TestService.ITestService"></endpoint>

        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8080/" />
          </baseAddresses>
        </host>
      </service>
    </services>

  </system.serviceModel>
TestService.svc.cs

namespace WCF_TestService
{
    [ServiceContract]
    public interface ITestService
    {
        [OperationContract]
        string GetMessage(string name);
    }
}
断点设置在
return
上,提示消息为
当前不会命中断点。没有为此文档加载任何符号

namespace WCF_TestService
{
    public class TestService : ITestService
    {
        public string GetMessage(string name)
        {
            return $"Hello {name}";
        }
    }
}
客户端

客户端是控制台应用程序

namespace Client
{
    class Program
    {
        static void Main(string[] args)
        {
            ServiceProxy.TestServiceClient client = new ServiceProxy.TestServiceClient();
            Console.WriteLine(client.GetMessage("John Smith"));
            Console.ReadLine();
        }
    }
}

也许这个回答和这个话题是一样的

  • 您需要将调试器附加到运行wcf服务的进程

    • 如果在iis中,则需要附加到相应的w3p.exe进程

    • 如果在独立应用程序或windows服务中,请附加到exe的名称

  • 在VisualStudio中,调试器菜单上有一个“附加到进程”。打开相关代码,设置一个断点,并调用导致该代码路径执行的服务

  • 在调试之外,使用带有可切换级别的.net跟踪是了解发生了什么的好方法。我通常设置sys internals debugview以颜色突出显示错误和警告,并在运行代码或测试时不断运行它。工作时,我周围视觉中的彩色线条会发现问题


    请尝试与系统管理员一起运行Visual Studio。可能您选择了错误的进程,或者运行的版本不是调试版本

    备选方案


    您可以在两个项目中使用右键单击,然后在“调试”->“启动新实例”中单击。Visual Studio以调试模式启动这两个项目。

    根据您对同一解决方案中的两个项目以及WCF未自托管的评论,您需要将解决方案配置为具有多个启动项目

    在解决方案资源管理器中,选择解决方案,单击鼠标右键,然后选择“属性”。在弹出窗口中展开“公共属性”选择,然后单击“启动项目”。单击多个启动项目并选择您的项目和生成操作。同时设置适当的顺序(本例中为WCF优先)

    另外,不要忘记更改控制台应用程序的端点地址,以指向wcf项目正在运行的相应IIS端口。在运行时,为调试和生产设置配置转换可能是您的最佳选择,这样您就不会在配置中不断切换这些端口


    如果创建console项目的唯一原因是与WCF服务交互以进行测试,那么我建议您改用WCF测试客户端。默认情况下,它应该安装在任何VS实例上。

    项目是否包含在同一个解决方案中?WCF服务是通过IIS运行还是自托管?@TravisActon它们位于同一解决方案中。它正在通过IIS10运行。我已尝试附加
    w3wp.exe
    进程,但没有成功。请尝试与系统管理员一起运行Visual Studio。可能您选择了错误的进程,或者运行的版本不是调试版本。您可以在两个项目中使用右键单击,然后在“调试”->“启动新实例”中单击。VisualStudio以调试模式启动这两个项目。谢谢Travis,这样就可以了。另一个问题是,为什么正常附加过程对这种类型的项目设置不起作用?@JasonTang normal attach应该可以正常工作,如果您的代码部署到本地IIS,但您必须更改IIS bin目录重建的生成路径,然后运行,以便所有内容都完全是最新的。我总是发现这样做更灵活/更不敏感,尤其是在项目开发中期。