簡體   English   中英

如何通過ASP.NET並排托管WCF中的服務調試

[英]How to debug a service in hosting WCF side-by-side with ASP.NET

我有一個簡單的托管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>

ITestService.cs

namespace WCF_TestService
{
    [ServiceContract]
    public interface ITestService
    {
        [OperationContract]
        string GetMessage(string name);
    }
}

TestService.svc.cs

斷點在return設置,並且提示消息為The breakpoint will not currently be hit. No symbols have been loaded for this document The breakpoint will not currently be hit. No symbols have been loaded for this document

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未被自我托管的評論,您需要將解決方案配置為具有多個啟動項目。

在解決方案資源管理器中,選擇解決方案,右鍵單擊並選擇屬性。 在彈出窗口中展開“公共屬性”選擇,然后單擊“啟動項目”。 單擊多個啟動項目,然后選擇您的項目並進行構建。 還要設置適當的順序(在這種情況下,請先設置WCF)

同樣不要忘記更改控制台應用程序的終結點地址,使其指向運行時wcf項目在其上運行的相應IIS端口,為調試和設置prod設置配置轉換可能最符合您的利益,因此您不必不斷地將這些切換到您的配置中。

如果創建控制台項目的唯一原因是要與WCF服務進行交互以進行測試,那么我建議您改用WCF Test CLient。 默認情況下,應將其安裝在任何VS實例上。

可能此響應與此主題相同。

如何調試WCF程序

  1. 您需要將調試器附加到運行wcf服務的進程。

    • 如果在iis中,則需要附加到相應的w3p.exe進程。

    • 如果在獨立的應用程序或Windows服務中,請附加到您的exe名稱。

  2. 在Visual Studio中,調試器菜單上有一個“附加到進程”。 打開相關代碼,設置一個斷點,然后調用導致該代碼路徑執行的服務。

在調試之外,使用具有可切換級別的.net跟蹤是了解正在發生的事情的好方法。 我通常會設置sys internals debugview的顏色以突出顯示錯誤和警告,並在運行代碼或測試時不斷使其運行。 工作時,我周圍視線中的彩色線條會發現問題。

嘗試與系統管理員一起運行Visual Studio。 也許您使用了錯誤的進程,或者運行的版本不是調試版本。

備選

您可以在兩個項目中單擊右鍵,然后單擊“調試”->“啟動新實例”。 Visual Studio以調試模式啟動兩個項目。

暫無
暫無

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

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