0
votes

I keep getting this error when I run the test client

Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata.

Cannot obtain Metadata from http://localhost:50507/Service1.svc If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error URI: http://localhost:50507/Service1.svc Metadata contains a reference that cannot be resolved: 'http://localhost:50507/Service1.svc'. The requested service, 'http://localhost:50507/Service1.svc' could not be activated. See the server's diagnostic trace logs for more information.HTTP GET Error URI: http://localhost:50507/Service1.svc There was an error downloading 'http://localhost:50507/Service1.svc'. The request failed with the error message:-- The type 'AgeCalculator.Service1', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found.

I have already exposed the metadata of the service with the following code in the web.config file

<system.serviceModel>
<services>
  <service name="AgeCalculator.CalculateAge" behaviorConfiguration="MetadataBehavior">
    <endpoint address=""
              binding="basicHttpBinding" contract="AgeCalculator.IService1">
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
    <endpoint address="http://localhost/Service1.svc" binding="basicHttpBinding" contract="AgeCalculator.IService1"/>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="MetadataBehavior">
      <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
      <serviceMetadata httpGetEnabled="true"/>
    </behavior>
  </serviceBehaviors>
</behaviors>
<protocolMapping>
    <add binding="basicHttpsBinding" scheme="http" />
</protocolMapping>    
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />

I have looked at all current documentation and don't know what the issue is. May be a naming convention as I am brand new to WCF but not seeing this. I have scoured the internet and exposing the metadata articles to apply fixes and nothing has worked to date

1
have you tried specifying a specific port such as 8000 as seen in many msdn docs for your service to listen on? <endpoint address="localhost:8000/Service1.svc" binding="basicHttpBinding" contract="AgeCalculator.IService1"/>David Yenglin
1) which version of .net are you using? (4.6.2, 4.7, core?) 2) could you please check the /bin/debug/ folder for your project to confirm that it is there and contains files like AgeCalculator.dll.tgolisch
Is your service name correct here - "AgeCalculator.CalculateAge" ? below its Service1Vishnu

1 Answers

0
votes

Since you don't seem to be using the default port, it is best to specify the port in your service binding. Change your service definition like this:

<services>
  <service name="AgeCalculator.CalculateAge" behaviorConfiguration="MetadataBehavior">
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:50507/" />
      </baseAddresses>
    </host>
    <endpoint address="" 
        binding="basicHttpBinding" contract="AgeCalculator.IService1" />
    <endpoint address="mex" 
        binding="mexHttpBinding" contract="IMetadataExchange"/>
    <endpoint address="http://localhost:50507/Service1.svc" 
        binding="basicHttpBinding" contract="AgeCalculator.IService1"/>
  </service>
</services>