无法调试 WCF 服务消息 [英] Unable to debug WCF service message

查看:21
本文介绍了无法调试 WCF 服务消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

当我运行我的客户端并从我的服务调用一个方法时,我收到一条消息说无法自动调试'Home.Service'.无法调试远程过程.这通常表明尚未启用调试服务器."

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>

已在客户端和服务器的 app.config 中添加.

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?

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

Added more info based on feedback questions

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

  • 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?)

    推荐答案

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

    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.

    为了解决这个问题,我首先开启了WCF追踪.这表明 WCF 正在抛出 MessageSecurityException:

    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.

    这提示我查看客户端的绑定设置.结果是我没有在我的自定义绑定中添加所需的安全元素.由于我是通过代码执行此操作的,因此我需要以下内容(注意第 3 行):

    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, });
    

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

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

    这篇关于无法调试 WCF 服务消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆