title: To call a Self Hosted WCF service from another Net.Tcp WCF service running on IIS 7
body: <p>I have a NetTcp Self Hosting service running on my client machine, and there is another NetTcp service running on IIS on the server. I am trying to consume the self hosted service from the service in IIS. It is throwing an exception with a timeout error.</p>
  
  <p>I used the WCF Test Client to test the self hosted service and it works fine. Also, I wrote a sample C# application which calls the self-hosted service and that works fine too. It is only when a service on IIS attempting to call, this is failing.</p>
  
  <p>My guess it there must be some security setting on IIS which is preventing out going calls, and hence the time out. Any clue?</p>
  
  <p><strong>Code to make the call to the Self Hosting service:</strong></p>
  
  <pre><code>private object CallClient(string message)
      {
          var myBinding = new NetTcpBinding(SecurityMode.None);
          var myEndpoint = new EndpointAddress("net.tcp://&lt;myIP&gt;:8188/MessageReceiverService/");
          var myChannelFactory = new ChannelFactory&lt;IMessageReceiverService&gt;(myBinding, myEndpoint);
  
          IMessageReceiverService client = null;
          var result = new MessageCenterResponse { Result = message };
  
          try
          {
              client = myChannelFactory.CreateChannel();
              result.Result += client.TestMethod("Shankar");
          }
          catch (Exception ex)
          {
              if (client != null)
              {
                  ((ICommunicationObject)client).Abort();
              }
              result.Result += "Exception!!" + myEndpoint.Uri + " - " + ex.Message;
          }
          finally
          {
              ((ICommunicationObject)client).Close();
          }
  
          return result;
      }
  </code></pre>
  
  <p><strong>Message Receiver Service (on the self-hosted service):</strong></p>
  
  <pre><code>public bool TestMethod(string testMessage)
      {
          return testMessage.Equals("Shankar");
      }
  </code></pre>
  
  <p>The above code works fine when called from an independent application, but fails when called from IIS after the line: <code>client.TestMethod("Shankar");</code></p>
  
  <p><strong>This is how I start the Self-Hosted Service:</strong></p>
  
  <pre><code>private void StartMessageCenterService()
      {
          var tcpUrl = new Uri("net.tcp://&lt;myIP&gt;:8188/MessageReceiverService/");
          var messageCenterHost = new ServiceHost(typeof(MessageReceiverService), tcpUrl);
  
          messageCenterHost.Faulted += MessageCenterHost_Faulted;
  
          messageCenterHost.Open();
      }
  </code></pre>
  
  <p><strong>Self-Hosted WebService code in App.config:</strong></p>
  
  <pre><code>&lt;services&gt;
    &lt;service name="MessageCenter.Proxy.VirtualServer.MessageReceiverService" behaviorConfiguration="DebugServiceBehavior"&gt;
      &lt;endpoint address=""
                binding="netTcpBinding"
                bindingConfiguration="InsecureTcp"
                behaviorConfiguration="LargeDataEndpointBehavior"
                contract="MessageCenter.Common.Interfaces.IMessageReceiverService"&gt;
      &lt;/endpoint&gt;
      &lt;endpoint address="mex"
                binding="mexTcpBinding"
                contract="IMetadataExchange" /&gt;
    &lt;/service&gt;
  &lt;/services&gt;
  </code></pre>