title: Can I call a method in a Self-Hosted WCF Service locally?
body: <p>I have a WCF Service contract which is basically the Publish Subscriber pattern.</p>
  
  <p>The WCF Service is hosted inside the Windows Service that I want to publish from. The Clients subscribe to messages and when the Windows Service does something it publishes to all clients.</p>
  
  <p>To host the service I have declared a ServiceHost class and the Contract Class has a method which is not flagged in the Interface but is implemented in the Class to publish.</p>
  
  <p>I want to be able to call this method locally (not going through WCF) which then publishes the message via Callbacks.</p>
  
  <p>I can't seem to get from ServiceHost to the instance of the Contract Class.</p>
  
  <p>Is this possible and if so how? I know the work around is to have a client built into the service as well, but it seems a bit strange creating a client to connect to itself.</p>
  
  <p>Thanks in advance</p>
  
  <p>DJIDave</p>
  
  <p>app.config</p>
  
  <pre><code>&lt;system.serviceModel&gt;
      &lt;services&gt;
        &lt;service behaviorConfiguration="Processor.Wcf.ServiceBehavior"
          name="Processor.Wcf.ProcessorService"&gt;
          &lt;endpoint address="net.tcp://localhost:9000/processor/service"
                binding="netTcpBinding" name="procService"
                bindingConfiguration="netTcpBindingConfig"
                contract="Processor.Wcf.IProcessorService"/&gt;
          &lt;endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /&gt;
            &lt;host&gt;
              &lt;baseAddresses&gt;
                &lt;add baseAddress="http://localhost:8732/Design_Time_Addresses/Processor.Wcf/Service1/" /&gt;
              &lt;/baseAddresses&gt;
            &lt;/host&gt;
        &lt;/service&gt;
      &lt;/services&gt;
      &lt;behaviors&gt;
        &lt;serviceBehaviors&gt;
          &lt;behavior name="Processor.Wcf.ServiceBehavior"&gt;
            &lt;!-- To avoid disclosing metadata information, 
            set the value below to false and remove the metadata endpoint above before deployment --&gt;
            &lt;serviceMetadata httpGetEnabled="True"/&gt;
            &lt;!-- To receive exception details in faults for debugging purposes, 
            set the value below to true.  Set to false before deployment 
            to avoid disclosing exception information --&gt;
            &lt;serviceDebug includeExceptionDetailInFaults="False" /&gt;
          &lt;/behavior&gt;
        &lt;/serviceBehaviors&gt;
      &lt;/behaviors&gt;
      &lt;bindings&gt;
        &lt;netTcpBinding&gt;
          &lt;binding name="netTcpBindingConfig"
                   closeTimeout="00:01:00"
                   openTimeout="00:01:00"
                   receiveTimeout="00:10:00"
                   sendTimeout="00:01:00"
                   transactionFlow="false"
                   transferMode="Buffered"
                   transactionProtocol="OleTransactions"
                   hostNameComparisonMode="StrongWildcard"
                   listenBacklog="10"
                   maxBufferPoolSize="524288"
                   maxBufferSize="65536"
                   maxConnections="10"
                   maxReceivedMessageSize="65536"&gt;
            &lt;readerQuotas maxDepth="32"
                          maxStringContentLength="8192"
                          maxArrayLength="16384"
                          maxBytesPerRead="4096"
                          maxNameTableCharCount="16384" /&gt;
            &lt;reliableSession ordered="true"
                             inactivityTimeout="00:10:00"
                             enabled="false" /&gt;
            &lt;security mode="Transport"&gt;
              &lt;transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" /&gt;
            &lt;/security&gt;
          &lt;/binding&gt;
        &lt;/netTcpBinding&gt;
      &lt;/bindings&gt;
  
    &lt;/system.serviceModel&gt;
  </code></pre>