调试 WCF 项目

发布于 2024-11-28 23:32:43 字数 1047 浏览 0 评论 0原文

我构建了一个包含 4 个项目的小解决方案:

  • 合同:包含我的(t4 生成的)实体和我的服务的接口

  • 服务:包含我的(t4 生成的)上下文和我的服务的实现

  • 主机:包含托管服务的最低限度

ServiceHost host = new ServiceHost(typeof(InleerAppService));

try
{
    host.Open();

    Console.WriteLine("The service is ready!");
    Console.ReadKey();

    host.Close();
}
catch (CommunicationException cex)
{
    Console.WriteLine(cex.Message);
}
  • 客户端:

varfactory = new ChannelFactory(“InleerAppService”);

IInleerAppService service = factory.CreateChannel();
var result = service.ReturnInput("test string"); // just returns the input string, this works!

Console.WriteLine(result);

var result2 = service.GetAllCompanies(); // this doesn't and crashes the client

foreach (Company c in result2)
{
    Console.WriteLine(c.Name);
}

Console.ReadKey();

你明白我想弄清楚发生了什么事。但我真的不明白如何调试这个。首先,我使用 ctrl+F5 启动主机,然后启动客户端。但这不允许我进行调试。我应该如何使用此设置来实现这一点?我知道还有更多使用服务的方法,但对于这一部分,我只想重点关注此设置。

I constructed a little solution containing 4 projects:

  • Contract: contains my (t4 generated) entities and interface to my service

  • Service: contains my (t4 generated) context and implementation of my service

  • Host: contains the bare minimum to host a service

ServiceHost host = new ServiceHost(typeof(InleerAppService));

try
{
    host.Open();

    Console.WriteLine("The service is ready!");
    Console.ReadKey();

    host.Close();
}
catch (CommunicationException cex)
{
    Console.WriteLine(cex.Message);
}
  • Client:

var factory = new ChannelFactory("InleerAppService");

IInleerAppService service = factory.CreateChannel();
var result = service.ReturnInput("test string"); // just returns the input string, this works!

Console.WriteLine(result);

var result2 = service.GetAllCompanies(); // this doesn't and crashes the client

foreach (Company c in result2)
{
    Console.WriteLine(c.Name);
}

Console.ReadKey();

You understand I would like to figure out what is going. But I don't really understand how I can debug this. First I start the host with ctrl+F5, then the client. But this doesn't allow me to debug. How should I go to that, using this setup? I know there are more ways to work with services, but for this part I'd just want to focus on this setup.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暖心男生 2024-12-05 23:32:43

您可以设置解决方案来启动多个项目,只需按 F5 即可。要进行设置,请右键单击解决方案并转到属性。在公共属性下选择启动项目。并选择您的服务和客户端项目来启动。

另一种调试方式是选择服务项目,右键进入调试->调试。启动新实例。接下来,对客户项目做同样的事情。现在您应该让服务项目和客户端项目都在调试模式下运行。

You can setup the solution to start multiple projects and just hit F5. To set this up, right click on the solution and go to properties. Select start up project under common properties. And choose both your service and client projects for startup.

Another way to debug is to select the service project, right click and go to debug -> start new instance. Next, do the same thing for client project. Now you should have both service and client projects running under debug mode.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文