WCF Service Base Address Http and netTcp

inutan picture inutan · Jan 6, 2010 · Viewed 29.8k times · Source

I have two base addresses defined in my WCF Service config file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>      
  <system.diagnostics>
    <sources>
      <source name="System.ServiceModel" switchValue="Warning, ActivityTracing"
        propagateActivity="true">
        <listeners>
          <add type="System.Diagnostics.DefaultTraceListener" name="Default">
            <filter type="" />
          </add>
          <add name="ServiceModelTraceListener">
            <filter type="" />
          </add>
        </listeners>
      </source>
    </sources>
    <sharedListeners>
      <add initializeData="C:\WCF Service Logs\app_tracelog.svclog"
        type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
        name="ServiceModelTraceListener" traceOutputOptions="DateTime, Timestamp">
        <filter type="" />
      </add>
    </sharedListeners>
  </system.diagnostics>
  <system.serviceModel>
    <bindings>
      <netTcpBinding>
        <binding name="netTcp" maxBufferPoolSize="50000000" maxReceivedMessageSize="50000000">
          <readerQuotas maxDepth="500" maxStringContentLength="50000000" maxArrayLength="50000000" maxBytesPerRead="50000000" maxNameTableCharCount="50000000" />
          <security mode="None"></security>
        </binding>
      </netTcpBinding>
    </bindings>
    <services>
      <service behaviorConfiguration="ReportingComponentLibrary.TemplateServiceBehavior"
        name="ReportingComponentLibrary.TemplateReportService">
        <endpoint address="TemplateService" binding="netTcpBinding" bindingConfiguration="netTcp"
          contract="ReportingComponentLibrary.ITemplateService"></endpoint>
        <endpoint address="ReportService" binding="netTcpBinding" bindingConfiguration="netTcp"
          contract="ReportingComponentLibrary.IReportService"/>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="net.tcp://localhost:8001/TemplateReportService" />
            <add baseAddress="http://localhost:8181/TemplateReportService"  />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ReportingComponentLibrary.TemplateServiceBehavior">
          <serviceMetadata httpGetEnabled="True"/>
          <serviceDebug includeExceptionDetailInFaults="True" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

And although I have set endpoint binding as netTcpBinding,
I am only able to access my WCF service with base address:

http://localhost:8181/TemplateReportService

and not with

net.tcp://localhost:8001/TemplateReportService

How can I make my service access with netTcp address?

Answer

marc_s picture marc_s · Jan 6, 2010

You defined a Net.TCP base address to be:

net.tcp://localhost:8001/TemplateReportService

Your endpoints with Net TCP are:

<endpoint address="TemplateService" 

and

<endpoint address="ReportService" 

So their complete service address will be "netTcp base address" + "relative address as defined on the <endpoint> element" - this gives:

net.tcp://localhost:8001/TemplateReportService/TemplateService

and

net.tcp://localhost:8001/TemplateReportService/ReportService

respectfully.

Can you use them at these addresses??

Also - you defined a "mex" (metadata exchange) endpoint for the HTTP protocol - that's why you can see something when you navigate to the HTTP address. But you did not specify a MEX endpoint for netTcp.