Search code examples
asp.netwcfiis-7wcf-binding

WCF netTcpBinding: why can't I debug and why not stable?


I have created a WCF service hosted in an ASP.NET web application, with netTcpBinding. I want to make it run, but I'm always getting the "object not set to a reference"-error.

I first created my service and tested it using the default bindings. It worked, I got my expected results returned.

As I don't want to run it through http, but through tcp, I changed my bindings as follow:

  <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" />

In the project properties, I've changed under the web tab that it should run under "Local IIS". Set the project URL to http://localhost/be.xxx.xxx.WCF and clicked the "Create Virtual Directory"-button.

enter image description here

I have also changed my IIS settings:

  • Application pool to .Net Framework v4.0.30319, Integrated
  • Under "Advanced Settings", I've added "net.tcp" for Enabled Protocols.

My Windows services "Net.Tcp Listener Adapter" and "Net.TCP Port Sharing Service" are both running.

I can browse to http://localhost/be.xxx.xxx.WCF/Leasing.svc, telling me that I have created a service.

So when I start debugging by hitting F5 (VS is running under administrator rights), I get the following screen: enter image description here

OK, when I start the stand-alone WCF Test Client, and I reference to http://localhost/be.xxx.xxx.WCF/Leasing.svc/mex, it loads the functions: enter image description here

First, it was totally giving me the nothing saying "Object reference not set to an instance of an object" exception. Just while setting up this question, it ran, giving me back the expected results. I couldn't believe why it ran this time, so I closed the WCF Test Client again, and retried my effort. Now it is giving me again the "Object reference not set to an instance of an object" exception. enter image description here

I also tried adding the service reference to a test console application, but this is giving me the same problems.

So, why can't I debug in Visual Studio (~metdata not found), and why doesn't seem it to be stable (running once)?


Solution

  • Have you tried to define the http mex binding