WCF netTcpBinding:为什么我不能调试,为什么不稳定?

时间:2014-09-30 09:45:44

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

我使用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选项卡下更改了它应该在“Local IIS”下运行。将项目URL设置为http://localhost/be.xxx.xxx.WCF,然后单击“创建虚拟目录”按钮。

enter image description here

我还更改了我的IIS设置:

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

我的Windows服务“Net.Tcp侦听器适配器”和“Net.TCP端口共享服务”都在运行。

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

因此,当我通过点击F5(VS在管理员权限下运行)开始调试时,我得到以下屏幕: enter image description here

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

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

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

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

1 个答案:

答案 0 :(得分:1)

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

相关问题