无法调试 WCF 服务消息

发布于 2024-12-07 03:56:06 字数 811 浏览 0 评论 0原文

我有一个带有 WCF 服务和客户端的 Visual Studio 2008 解决方案。

当我运行客户端并从服务调用方法时,我收到一条消息“无法自动调试‘Home.Service’。无法调试远程过程。这通常表明服务器上尚未启用调试。 ”

我用谷歌搜索了一下,并尝试了以下方法。

<system.web>
   <compilation debug="true" />
</system.web>

已添加到客户端和服务器上的 app.config 中。

我还确保该项目正在调试模式下编译。

还有什么可能导致此消息?

编辑:根据反馈问题添加了更多信息

  • 它正在使用 wsHttpBinding
  • 我已设置

    ;
    
  • 我正在使用

    var service = new HomeReference.HomeServiceClient();
    service.ClientCredentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
    

不幸的是,第一次在我的服务上调用方法时出现错误。我可以关闭消息框,应用程序将继续工作。不过,服务器上抛出的任何异常都不会传播回客户端(我认为应该如此?)

I've got a Visual Studio 2008 solution with a WCF service, and a client.

When I run my client, and call a method from my service I get a message saying "Unable to automatically debug 'Home.Service'. The remote procedure could not be debugged. This usually indicates that debugging has not been enabled on the server."

I've googled around, and have tried the following.

<system.web>
   <compilation debug="true" />
</system.web>

has been added in app.config on both the client and the server.

I have also made sure that the project is being compiled in Debug mode.

What else could be causing this message?

Edit: Added more info based on feedback questions

  • It is using wsHttpBinding
  • I have set

    <serviceDebug includeExceptionDetailInFaults="true"/>
    
  • I am using

    var service = new HomeReference.HomeServiceClient();
    service.ClientCredentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
    

Unfortunately the error shows up the first time I call a method on my Service. I can dismiss the messagebox, and the application continues working. Any Exceptions thrown on the server at not propagated back to the client though (I assume it should?)

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

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

发布评论

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

评论(12

何以心动 2024-12-14 03:56:06

我与这个完全相同的错误斗争了一个多小时,然后我重新启动了 VS2008,它神奇地自行修复了。尝试一下,因为它可能会节省您一些时间。

I was fighting with this exact same error for over an hour and low and behold I restarted VS2008 and it magically fixed itself. Give it a try as it might save you some time.

乱了心跳 2024-12-14 03:56:06

就我而言,问题是客户端和服务器上的安全设置不匹配。我使用的是这样的自定义绑定:

<customBinding>
    <binding name="AuthorisedBinaryHttpsBinding" receiveTimeout="00:03:00" sendTimeout="00:03:00">
      <!-- this next element caused the problem: -->
      <security authenticationMode="UserNameOverTransport">
      </security>
      <binaryMessageEncoding>
        <readerQuotas maxDepth="100" maxStringContentLength="1000000"
          maxArrayLength="655360000" />
      </binaryMessageEncoding>
      <httpsTransport />
    </binding>
  </customBinding>

当我删除上面突出显示的安全元素时,“无法自动调试”消息的问题就消失了。

为了解决这个问题,我首先打开了WCF 跟踪。这表明 WCF 抛出了 MessageSecurityException

安全处理器无法找到
消息中的安全标头。这
可能是因为该消息是
不安全的故障或因为有
之间的结合不匹配
沟通各方。这个可以
如果服务配置为
安全且客户端未使用
安全。

这让我查看客户端的绑定设置。事实证明,我没有将所需的安全元素添加到我的自定义绑定中。由于我是通过代码执行此操作,因此我需要以下内容(请注意第三行):

  var binding = new CustomBinding(
      binaryEncoding,
      SecurityBindingElement.CreateUserNameOverTransportBindingElement(),
      new HttpsTransportBindingElement { MaxReceivedMessageSize = MaxMessageSize, });

至于为什么 Visual Studio 显示该错误,我不知道 - 在我看来这是一个错误。

In my case the problem turned out to be a mismatch between security settings on client and server. I was using a custom binding like this:

<customBinding>
    <binding name="AuthorisedBinaryHttpsBinding" receiveTimeout="00:03:00" sendTimeout="00:03:00">
      <!-- this next element caused the problem: -->
      <security authenticationMode="UserNameOverTransport">
      </security>
      <binaryMessageEncoding>
        <readerQuotas maxDepth="100" maxStringContentLength="1000000"
          maxArrayLength="655360000" />
      </binaryMessageEncoding>
      <httpsTransport />
    </binding>
  </customBinding>

When I removed the security element that I've highlighted above the problem with the "Unable to automatically debug" message went away.

To solve the problem I first turned on WCF tracing. This showed me that WCF was throwing a MessageSecurityException:

Security processor was unable to find
a security header in the message. This
might be because the message is an
unsecured fault or because there is a
binding mismatch between the
communicating parties. This can
occur if the service is configured for
security and the client is not using
security.

That pointed me to look at the Binding settings on the client side. It turned out that I hadn't added the required security element to my custom binding there. Since I was doing this through code, I needed the following (note the 3rd line):

  var binding = new CustomBinding(
      binaryEncoding,
      SecurityBindingElement.CreateUserNameOverTransportBindingElement(),
      new HttpsTransportBindingElement { MaxReceivedMessageSize = MaxMessageSize, });

As to why Visual Studio was showing that error, I've no idea - looks to me to be a bug.

忆依然 2024-12-14 03:56:06

自动附加到服务具有以下限制:

  • 该服务必须是您正在调试的 Visual Studio 解决方案的一部分。

  • 必须托管该服务。它可能是网站项目(文件系统和 HTTP)、Web 应用程序项目(文件系统和 HTTP)或 WCF 服务库项目的一部分。 WCF 服务库项目可以是服务库或工作流服务库。

  • 必须从 WCF 客户端调用该服务。

  • 必须使用 app.config 或 Web.config 文件中的以下代码启用调试:

    ;
      <编译调试=“true”/>
    
    

请参阅 WCF 调试的限制

此外,如果两个项目(客户端和服务)位于同一解决方案中,但将在不同的进程中运行(例如,如果您使用本地 IIS 服务器)为了发展并且在与其使用的服务不同的应用程序池上运行您的 Web 应用程序),您可能需要为解决方案启用“多个启动项目”(在解决方案属性上 - > 启动项目),以便调试器可以附加到两者。

为了避免每次调试时都显示服务浏览器窗口,您可以将“启动操作”(在服务项目属性上)设置为“不要打开页面。等待外部应用程序的请求”。

这是个人经验,可能对其他人有帮助。

Automatically attaching to a service has the following limitations:

  • The service must be part of the Visual Studio solution you are debugging.

  • The service must be hosted. It may be part of a Web Site Project (File System and HTTP), Web Application Project (File System and HTTP), or WCF Service Library project. WCF Service Library projects can be either Service Libraries or Workflow Service Libraries.

  • The service must be invoked from a WCF client.

  • Debugging must be enabled with the following code in the app.config or Web.config file:

    <system.web>
      <compilation debug="true" />
    </system.web>
    

See Limitations on WCF Debugging

In addition, if both projects (client and service) are in the same solution but will run in different processes (for example if you are using your local IIS Server for development and are running your web application on a different application pool than the service it consumes), you may need to enable "Multiple startup projects" for the solution (on Solution Properties -> Startup Project) so that the debugger can attach to both.

To avoid the service browser window to show up every time you debug, you may set the "Start Action" (on service project properties) to "Don't open a page. Wait for request from external application."

This is from personal experience and may help others.

暖树树初阳… 2024-12-14 03:56:06

您可能会看到此错误的另一个原因(我相信我就是这种情况)是如果您在 64 位 Windows 中运行。显然 Visual Studio 没有任何 x64 调试器支持。

您可以通过更改使用应用程序的平台目标来解决此问题:

项目属性 ->构建->将“平台目标”更改为“x86”。

不幸的是,这对我不起作用,因为我正在尝试在 Windows Azure Development AppFabric 中运行,这似乎要求所有内容都以 64 位模式运行!

The other reason you might see this error (and I believe is the case for me) is if you're running in 64bit Windows. Apparently Visual Studio doesn't have any x64 debugger support.

You can work around this by changing the Platform Target for the consuming application:

Project Properties -> Build -> Change "Platform Target" to "x86".

Unfortunately this won't work for me as I'm trying to run in the Windows Azure Development AppFabric which seems to require everything to run in 64bit mode!

二手情话 2024-12-14 03:56:06

我也遇到了同样的问题。我在客户端和客户端都发生了变化。服务配置文件(如

编译调试)设置为 true。

这对我有用。

I also got the same problem. I changed in both client & service config files like

Compilation debug is set to true.

This worked for me.

像极了他 2024-12-14 03:56:06

您是否尝试

    <serviceBehaviors>

  <serviceDebug includeExceptionDetailInFaults="true"/>
            </behavior>
        </serviceBehaviors>

过出于调试目的?

编辑:没关系,我想我误解了这个问题

Have you tried

    <serviceBehaviors>

  <serviceDebug includeExceptionDetailInFaults="true"/>
            </behavior>
        </serviceBehaviors>

For debugging purposes?

Edit : nevermind, I think I misunderstood the question

蹲墙角沉默 2024-12-14 03:56:06

我也遇到过类似的问题,结果是由于 IIS 站点/虚拟目录上未启用 Windows 身份验证。

您是否尝试过将身份验证模式设置为集成而不是匿名?
http://msdn.microsoft.com/en-us /library/x8a5axew(VS.80).aspx

I've had a similar problem and it turns out to have been due to Windows Authentication not being enabled on the IIS site/virtual directory.

Have you tried setting the authentication mode to Integrated instead of Anonymous?
http://msdn.microsoft.com/en-us/library/x8a5axew(VS.80).aspx

无声无音无过去 2024-12-14 03:56:06

在 Web 服务 web.config 中,确保编译调试设置为 true。
这应该可以解决你的问题!

In your web service web.config ensure that compilation debug is set to true.
That should fix your problem!

软糖 2024-12-14 03:56:06

就我而言,问题是完全不同的。我更改了网络服务上的操作名称,但忘记更新客户端。由于某种原因,这导致了“无法自动调试...”错误。

In my case the problem turned out to be something completely different. I had changed the name of an operation on the webservice and forgot to update the client. For some reason this resulted in the "Unable to automatically debug ..." error.

醉殇 2024-12-14 03:56:06

也可能是 IISExpress 和 IIS 使用相同的端口号。如果您在 Visual Studio 和 IISExpress 中开发 WCF 应用程序,然后在本地 IIS 上安装相同的应用程序,请确保不要在 IIS 和 IISExpress 中使用相同的端口号。使用相同的端口号将导致此错误消息。

It can also be that the same port number is used in IISExpress and IIS. If you are developing a WCF application in Visual Studio and IISExpress and then install the same application on your local IIS make sure not to use the same port number in IIS and IISExpress. Using the same port number will lead to this error message.

烟雨扶苏 2024-12-14 03:56:06

我在 Visual Studio 2017 中遇到了同样的问题。删除解决方案文件夹根目录中隐藏的 .vs 文件夹后,我能够再次调试。

I had the same issue in Visual Studio 2017. After deleting the hidden .vs folder in the root of the solution folder, I was able to debug again.

烟柳画桥 2024-12-14 03:56:06

在客户端中创建服务引用后添加此代码行。

MyWCFService.IService _proxy = new MyWCFService.IService();
_proxy.ClientCredentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials;

Add this line of code after you create your service reference in your client.

MyWCFService.IService _proxy = new MyWCFService.IService();
_proxy.ClientCredentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文