【问题标题】:WCF netTcpBinding: why can't I debug and why not stable?WCF netTcpBinding:为什么我不能调试,为什么不稳定?
【发布时间】:2014-11-24 21:29:51
【问题描述】:

我使用 netTcpBinding 创建了一个托管在 ASP.NET Web 应用程序中的 WCF 服务。我想让它运行,但我总是收到“对象未设置为引用”错误。

我首先创建了我的服务并使用默认绑定对其进行了测试。它奏效了,我得到了预期的结果。

由于我不想通过 http 运行它,而是通过 tcp,我将绑定更改如下:

  <system.serviceModel>
<services>
  <service name="be.xxx.xxx.WCF.Leasing">
    <endpoint address="" binding="netTcpBinding" bindingConfiguration="" contract="be.xxx.xxx.WCF.ILeasing" />
    <endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="" contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="net.tcp://localhost/be.xxx.xxx.WCF/Leasing.svc"/>
      </baseAddresses>
    </host>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior>
      <serviceMetadata httpGetEnabled="false" httpsGetEnabled="false" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />

在项目属性中,我在 Web 选项卡下更改了它应该在“本地 IIS”下运行。将项目 URL 设置为 http://localhost/be.xxx.xxx.WCF 并单击“创建虚拟目录”按钮。

我还更改了我的 IIS 设置:

  • 应用程序池到 .Net Framework v4.0.30319,集成
  • 在“高级设置”下,我为启用的协议添加了“net.tcp”。

我的 Windows 服务“Net.Tcp Listener Adapter”和“Net.TCP Port Sharing Service”都在运行。

我可以浏览到http://localhost/be.xxx.xxx.WCF/Leasing.svc,告诉我我已经创建了一个服务。

所以当我按 F5 开始调试时(VS 在管理员权限下运行),我得到以下屏幕:

好的,当我启动独立的 WCF 测试客户端并引用 http://localhost/be.xxx.xxx.WCF/Leasing.svc/mex 时,它会加载函数:

首先,它完全没有告诉我“对象引用未设置为对象的实例”异常。 就在设置这个问题时,它运行了,给了我预期的结果。 我无法相信这次为什么会运行,所以我再次关闭了 WCF 测试客户端,并重试了我的努力。现在它再次给了我“对象引用未设置为对象的实例”异常。

我还尝试将服务引用添加到测试控制台应用程序,但这给了我同样的问题。

那么,为什么我不能在 Visual Studio 中调试(~metdata not found),为什么它看起来不稳定(运行一次)?

【问题讨论】:

    标签: asp.net wcf iis-7 wcf-binding


    【解决方案1】:

    您是否尝试过定义 http mex 绑定

    【讨论】:

    • 我已经改变了&lt;endpoint address="mex" binding="mexHttpBinding" bindingConfiguration="" contract="IMetadataExchange" /&gt;,现在我可以在VS中调试了。谢谢
    • 虽然这似乎解决了 OP 的问题,但这个答案相当糟糕,因为没有解释或附加信息。如果您添加提供更多详细信息/信息的信息,那将是一个很好的答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多