title: WCF Metadata reference cannot be resolved
body: <p>I am having an issue where I can't add a service reference in Visual Studio 2010 via a URL.</p>
  
  <p>I have my HOST file setup to resolve <a href="http://mydomain.com" rel="nofollow">http://mydomain.com</a> locally, and setup my web.config file to reference this url.  However when I go to add a service reference by URL I get the following error:</p>
  
  <pre><code>Metadata contains a reference that cannot be resolved: 'http://mydomain.com/myservice.svc?wsdl'.
  
  The WSDL document contains links that could not be resolved.
  
  There was an error downloading 'http://mydomain.com/myservice.svc?xsd=xsd0'.
  
  The underlying connection was closed: An unexpected error occurred on a receive.
  
  Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
  
  An existing connection was forcibly closed by the remote host
  
  Metadata contains a reference that cannot be resolved: 'http://mydomain.com/myservice.svc'.
  
  There was no endpoint listening at http://mydomain.com/myservice.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
  
  The remote server returned an error: (404) Not Found.
  </code></pre>
  
  <p>The other URLS work fine: 
  <a href="http://mydomain.com/myservice.svc?wsdl" rel="nofollow">http://mydomain.com/myservice.svc?wsdl</a> and <a href="http://mydomain.com/myservice.svc" rel="nofollow">http://mydomain.com/myservice.svc</a></p>
  
  <p>Here is my web.config file:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;configuration&gt;
  
    &lt;system.web&gt;
      &lt;compilation debug="true" targetFramework="4.0" /&gt;
    &lt;/system.web&gt;
    &lt;system.serviceModel&gt;
  
      &lt;services&gt;
        &lt;!-- Note: the service name must match the configuration name for the service implementation. --&gt;
        &lt;service name="FuncWS.Email" behaviorConfiguration="ServiceType" &gt;
          &lt;!-- Add the following endpoint.  --&gt;
          &lt;endpoint address="myservice.svc" binding="webHttpBinding" contract="FuncWS.IEmail"&gt;&lt;/endpoint&gt;
          &lt;!-- Note: your service must have an http base address to add this endpoint. --&gt;
          &lt;endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" /&gt;
          &lt;host&gt;
            &lt;baseAddresses&gt;
              &lt;add baseAddress="http://mydomain.com"/&gt;
            &lt;/baseAddresses&gt;
          &lt;/host&gt;
        &lt;/service&gt;
      &lt;/services&gt;
      &lt;behaviors&gt;
        &lt;serviceBehaviors&gt;
          &lt;behavior name="ServiceType"&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;serviceHostingEnvironment multipleSiteBindingsEnabled="true" /&gt;
    &lt;/system.serviceModel&gt;
    &lt;system.webServer&gt;
      &lt;modules runAllManagedModulesForAllRequests="true"/&gt;
    &lt;/system.webServer&gt;
  &lt;/configuration&gt;
  </code></pre>