title: WCF Service to talk to another WCF Service
body: <p>I created a new Test WCF Application.  It runs fine with the Simple GetData method with the WCF Test Client when I run the solution in Visual Studio.  However I now want to add a Service Reference to an external WCF Service so that I can talk to it from this Web Service.  So the interface for me Service1 now looks like:</p>
  
  <pre><code>public interface IService1 : MyExternalService
  </code></pre>
  
  <p>Then on my service class where I have the simple GetData I can hit Implement Interfaces and I see all the methods for the External Web Service created:</p>
  
  <pre><code>     public class Service1 : IService1
          {
              public string GetData(int value)
              {
                  return string.Format("You entered: {0}", value);
              }
  
              public string ExternalMethod1(string a, string b)
              {
                  throw new NotImplementedException();
              }
  
  //etc 
  </code></pre>
  
  <p>However if I try to run this with the WCF Test Client - I get the following error message - <code>Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata.</code></p>
  
  <p>After I included the External Service Ref it updated my web.config to as below (note some actual urls scrubbed)</p>
  
  <pre><code>&lt;configuration&gt;
  
    &lt;appSettings&gt;
      &lt;add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" /&gt;
    &lt;/appSettings&gt;
    &lt;system.web&gt;
      &lt;compilation debug="true" targetFramework="4.5" /&gt;
      &lt;httpRuntime targetFramework="4.5"/&gt;
    &lt;/system.web&gt;
    &lt;system.serviceModel&gt;
      &lt;bindings&gt;
        &lt;wsHttpBinding&gt;
          &lt;binding name="WSHttpBinding_IExternalService"&gt;
            &lt;security&gt;
              &lt;message clientCredentialType="Certificate" /&gt;
            &lt;/security&gt;
          &lt;/binding&gt;
          &lt;binding name="WSHttpBinding_IExternalService1"&gt;
            &lt;security&gt;
              &lt;message clientCredentialType="Certificate" negotiateServiceCredential="false"
                algorithmSuite="Basic128" establishSecurityContext="false" /&gt;
            &lt;/security&gt;
          &lt;/binding&gt;
        &lt;/wsHttpBinding&gt;
      &lt;/bindings&gt;
      &lt;client&gt;
        &lt;endpoint address="http://service.com/ExternalService/ExternalService.svc"
          binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IExternalService"
          contract="ExternalService.IExternalService" name="WSHttpBinding_IExternalService"&gt;
          &lt;identity&gt;
            &lt;dns value="service.com" /&gt;
          &lt;/identity&gt;
        &lt;/endpoint&gt;
        &lt;endpoint address="http://service.com/ExternalService/ExternalService.svc/Java"
          binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IExternalService1"
          contract="ExternalService.IExternalService" name="WSHttpBinding_IExternalService1"&gt;
          &lt;identity&gt;
            &lt;dns value="service.com" /&gt;
          &lt;/identity&gt;
        &lt;/endpoint&gt;
      &lt;/client&gt;
      &lt;behaviors&gt;
        &lt;serviceBehaviors&gt;
          &lt;behavior&gt;
            &lt;!-- To avoid disclosing metadata information, set the values below to false before deployment --&gt;
            &lt;serviceMetadata httpGetEnabled="true" httpsGetEnabled="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;protocolMapping&gt;
          &lt;add binding="basicHttpsBinding" scheme="https" /&gt;
      &lt;/protocolMapping&gt;    
      &lt;serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /&gt;
    &lt;/system.serviceModel&gt;
    &lt;system.webServer&gt;
      &lt;modules runAllManagedModulesForAllRequests="true"/&gt;
      &lt;!--
          To browse web app root directory during debugging, set the value below to true.
          Set to false before deployment to avoid disclosing web app folder information.
        --&gt;
      &lt;directoryBrowse enabled="true"/&gt;
    &lt;/system.webServer&gt;
  
  &lt;/configuration&gt;
  </code></pre>