none
WCF Getting Started Tutorial - WCF service host cannot find any service metadata ... RRS feed

  • Question

  • I'm trying to work thru the WCF Getting Started tutorial using Visual Studio 2013 (Ultimate, if that makes any difference).

    I worked through the first two modules, entering code along the way as instructed.  No problems.

    I've gotten to the third step, "How to: Host and Run a Basic Windows Communication Foundation Service", and have again entered the code as instructed.

    On this third module, when I hit Start, the system thinks for a few seconds and then displays a message that starts "WCF service host cannot find any service metadata. ..."  At the same time, I get a message in the notifications area of the task bar (lower right corner) saying "WcfSvcHost - Your service(s) have been hosted.  Click here for detailed information."  When I click, I get a dialog box showing the service GettingStartedLib.CalculatorService with a status of "Stopped" and a blank "Metadata Address".

    Anyone know what gives? And please don't tell me that I need to edit my .config file because supposedly the Getting Started tutorial doesn't require it (unless, of course, Microsoft got their tutorial wrong ...).

    Thanx.

    Monday, February 2, 2015 4:31 AM

Answers

  • Richard,

    I am trying to go through the same tutorial and running into the same issues. This resolved it at least a little for me, and heads up, you do have to touch a config file. (I was hoping to avoid this as well...) If you open up App.config in GettingStartedLib, you'll find three places where it references IService1 or Service1 in URLs. You just need to change those to ICalculator and CalculatorService, respectively.

    And that should solve your issue!!! Just in time for you to run into another one. 

    If you try to run the service now, it is able to start up fine, but in the tutorial, it says to check that it works by navigating to the app's debug page at: http://localhost:8000/GettingStarted/CalculatorService

    Unfortunately, there's nothing to be found at this URL because the service is actually being hosted at: http://localhost:8733/Design_Time_Addresses/GettingStartedLib/CalculatorService/. You can find this URL in App.config as well and replace it. Run the service again, and this time the app's debug page URL should take you to a page that starts with: "You have created a service. To test this service, you will need to create a client and use it to call the service. You can do this using the svcutil.exe tool from the command line with the following syntax."

    This worked for me, and it seems like you went through the exact same steps and errors that I did, so I think this should fix it for you too!


    Friday, February 27, 2015 11:30 PM

All replies

  • Assuming that you're talking about this tutorial, the steps listed there are for a console application. It seems based on what you described that the type of project that you selected is a WCF Service Library (or a WCF Service Application). In the "to host the service" section of that tutorial, the code lists a "static void Main" method, so it points to a console application instead of a service application. Try creating a new project of the correct type, and you should be able to get it working.

    Carlos Figueira

    Monday, February 2, 2015 6:48 PM
    Moderator
  • Carlos,

    Thanks for getting back to me.  Yes, that's the tutorial.

    I understand your point about ServiceLibrary vs. Console App.  I believe I did elect the Host to be a Console App.  Here's my code for the GettingStartedHost project:

    // program.cs
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.ServiceModel;
    using GettingStartedLib;
    using System.ServiceModel.Description;
     
    namespace GettingStartedHost 
    {
    	class Program 
    	{
    		static void Main(string[] args) 
    		{
    			// Step 1 Create a URI to serve as the base address.
    			Uri baseAddress = new Uri("http://localhost:8000/GettingStarted/");
     
    			// Step 2 Create a ServiceHost instance
    			ServiceHost selfHost = new ServiceHost(typeof(CalculatorService), baseAddress);
     
    			try 
    			{
    				
    				// Step 3 Add a service endpoint.
    				selfHost.AddServiceEndpoint(typeof(ICalculator), new WSHttpBinding(), "CalculatorService");
     
    				// Step 4 Enable metadata exchange.
    				ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
    				smb.HttpGetEnabled = true;
    				selfHost.Description.Behaviors.Add(smb);
     
    				// Step 5 Start the service.
    				selfHost.Open();
    				Console.WriteLine("The service is ready.");
    				Console.WriteLine("Press <ENTER> to terminate service.");
    				Console.WriteLine();
    				Console.ReadLine();
     
    				// Close the ServiceHostBase to shutdown the service.
    				selfHost.Close();
    			}
    			catch (CommunicationException ce) 
    			{
    				Console.WriteLine("An exception occurred: {0}", ce.Message);
    				selfHost.Abort();
    			}
    		}
    	}
    }
    

    And, in case you're interested, here's the code for the GettingStartedLib project:

    // IService.cs <== INTERFACE

    using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.Text; namespace GettingStartedLib  { [ServiceContract(Namespace = "http://Microsoft.ServiceModel.Samples")] publicinterfaceICalculator  { [OperationContract] double Add(double n1, double n2); [OperationContract] double Subtract(double n1, double n2); [OperationContract] double Multiply(double n1, double n2); [OperationContract] double Divide(double n1, double n2); } }

    //Service1.cs   <== IMPLEMENATION OF INTERFACE (DUH)
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.Text;
     
    namespace GettingStartedLib 
    {
    	public class CalculatorService : ICalculator 
    	{
    		public double Add(double n1, double n2) 
    		{
    			double result = n1 + n2;
    			Console.WriteLine("Received Add({0},{1})", n1, n2);
    			// Code added to write output to the console window.
    			Console.WriteLine("Return: {0}", result);
    			return result;
    		}
     
    		public double Subtract(double n1, double n2) 
    		{
    			double result = n1 - n2;
    			Console.WriteLine("Received Subtract({0},{1})", n1, n2);
    			Console.WriteLine("Return: {0}", result);
    			return result;
    		}
     
    		public double Multiply(double n1, double n2) 
    		{
    			double result = n1 * n2;
    			Console.WriteLine("Received Multiply({0},{1})", n1, n2);
    			Console.WriteLine("Return: {0}", result);
    			return result;
    		}
     
    		public double Divide(double n1, double n2) 
    		{
    			double result = n1 / n2;
    			Console.WriteLine("Received Divide({0},{1})", n1, n2);
    			Console.WriteLine("Return: {0}", result);
    			return result;
    		}
    	}
    }
    

    The above is my code, but I copied it straight from the tutorial's web pages.  What am I missing?  Is it some configuration setting?  Supposedly, since the tutorial uses the "self hosting" approach, I don't have to mess with app.config (I think steps 3 & 4 are supposed to handle that part of it ...).  Could it be some solution/project property?  (And yes, the target framework is 4.5, in case you're wondering.)

    Your help is greatly appreciated!

         Richard

    Monday, February 2, 2015 7:17 PM
  • Richard,

    I am trying to go through the same tutorial and running into the same issues. This resolved it at least a little for me, and heads up, you do have to touch a config file. (I was hoping to avoid this as well...) If you open up App.config in GettingStartedLib, you'll find three places where it references IService1 or Service1 in URLs. You just need to change those to ICalculator and CalculatorService, respectively.

    And that should solve your issue!!! Just in time for you to run into another one. 

    If you try to run the service now, it is able to start up fine, but in the tutorial, it says to check that it works by navigating to the app's debug page at: http://localhost:8000/GettingStarted/CalculatorService

    Unfortunately, there's nothing to be found at this URL because the service is actually being hosted at: http://localhost:8733/Design_Time_Addresses/GettingStartedLib/CalculatorService/. You can find this URL in App.config as well and replace it. Run the service again, and this time the app's debug page URL should take you to a page that starts with: "You have created a service. To test this service, you will need to create a client and use it to call the service. You can do this using the svcutil.exe tool from the command line with the following syntax."

    This worked for me, and it seems like you went through the exact same steps and errors that I did, so I think this should fix it for you too!


    Friday, February 27, 2015 11:30 PM
  • Just copy paste this in your App.Config File for GettingStartedLib Project, I am very sure this would solve ypur problem if you're following the tutorial series from here: https://docs.microsoft.com/en-us/dotnet/framework/wcf/how-to-host-and-run-a-basic-wcf-service

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <appSettings>
        <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
      </appSettings>
      <system.web>
        <compilation debug="true" />
      </system.web>
      <!-- When deploying the service library project, the content of the config file must be added to the host's
      app.config file. System.Configuration does not support config files for libraries. -->
      <system.serviceModel>
        <services>
          <service name="GettingStartedLib.CalculatorService">
            <host>
              <baseAddresses>
                <add baseAddress = "http://localhost:8000/GettingStarted/CalculatorService" />
              </baseAddresses>
            </host>
            <!-- Service Endpoints -->
            <!-- Unless fully qualified, address is relative to base address supplied above -->
            <endpoint address="" binding="basicHttpBinding" contract="GettingStartedLib.ICalculator">
              <!--
                  Upon deployment, the following identity element should be removed or replaced to reflect the
                  identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity
                  automatically.
              -->
              <identity>
                <dns value="localhost"/>
              </identity>
            </endpoint>
            <!-- Metadata Endpoints -->
            <!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
            <!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
          </service>
        </services>
        <behaviors>
          <serviceBehaviors>
            <behavior>
              <!-- To avoid disclosing metadata information,
              set the values below to false before deployment -->
              <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>
              <!-- 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 -->
              <serviceDebug includeExceptionDetailInFaults="False" />
            </behavior>
          </serviceBehaviors>
        </behaviors>
      </system.serviceModel>
    </configuration>

    Sunday, November 19, 2017 12:27 PM