none
WCF error "The client was unable to retrieve service metadata. MAke sure the service is running and exposing metadata"

    Question

  • I have been dealing with this error for more than 3 hours. I dont see anything wrong in any place in my code.

    First I got the message box which say "The client was unable ........"  and when I click on the little icon when you try to run service, it says

    "The service cannot be started. This service has no endpoint defined. Please add at least one endpoint for the service in config file and try again"

    But this is not right, because I do have endpoints defined.

    This is "service tag" in app.config :

    <

    <

    <

    services> service name="Client_STS.ClientService" behaviorConfiguration="Client_STS.Service1Behavior"> endpoint address ="net.msmq://localhost/private/clientqueue" bindingConfiguration="NetMsmqBinding_IServer" binding="netMsmqBinding" contract="Client_STS.IClient">
    <
    identity> <dns value="hostname"/> </identity>
    </
    endpoint>
    <e
    ndpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> </service>
    </
    services>
    Friday, April 03, 2009 3:00 PM

Answers

  • From arhitectural point of view you should have two projects, a WCF Service Library project and a Windows Forms project.
    With this 'layout' you need to add the reference to the WCF Service Library assembly in you Forms project (and move the config file).

    If you want to put it all in the same project, I suggest you first create a Windows Forms project and then add the WCF service component to it (right-click the project and select Add -> Component -> WCF Service).

    You could change the type of you current project (right click the project, select Properties -> Application and change the Output type to Windows application) but you'll have to do some adjustments (implement the method Main).

    Service Library projects are compiled as DLLs and are not meant to be run directly as e.g. Console projects.

    Hope this helps!

    Regards,
    John
    • Marked as answer by Me.Saqib Tuesday, April 07, 2009 9:32 PM
    Friday, April 03, 2009 8:49 PM
  • I think you are right...Its the namespace issue but its really strange.

    If I have proj and I have class, I access the class name as <myproj>.className to create an object of it.

    So after removing all the <myproj> words, the  service finally pop up again .

    I changed

    <

    And

    endpoint address="net.msmq://localhost/private/clientqueue"  binding="netMsmqBinding" contract="Client_STS_SingleProj.IClient">
    To
    <endpoint address="net.msmq://localhost/private/clientqueue"  binding="netMsmqBinding" contract="IClient">

    and it worked. (STill having an issue)

    1. I never understood why IT WOULD DO THIS TO ME????
    2. I wanted to host my service in the form but again I m getting the default the box where your service is hosted on localhost and service methods on the side to test...

    <

    service name="Client_STS_SingleProj.ClientService" behaviorConfiguration="Client_STS.Service1Behavior">
    To
    <
    service name="ClientService" behaviorConfiguration="Client_STS.Service1Behavior">

     

    • Marked as answer by Me.Saqib Tuesday, April 07, 2009 9:31 PM
    Monday, April 06, 2009 4:54 PM
  • well in moving your code around you have taken the class out of the namespace and so thats why the config doesn;t work

    I have no idea what you mean by 2. - you need to run the .exe to run the service
    Richard Blewett, thinktecture - http://www.dotnetconsult.co.uk/weblog2
    • Marked as answer by Me.Saqib Tuesday, April 07, 2009 9:33 PM
    Monday, April 06, 2009 6:35 PM
  • The problem is that WCFServiceLibrary projects are "special" in that you can run them without providing your own host because teh WCFServiceHost process gets instantiated for you. Changing the project type doesn;t appear to change this behavior - the general idea is you create a second project to host the library - referencing the library from the hosting process - then you run the host and the service gets hosted. You need to remember to copy the configuration from the library to the hosting process as config files are application rather than library specific in .NET
    Richard Blewett, thinktecture - http://www.dotnetconsult.co.uk/weblog2
    • Marked as answer by Me.Saqib Tuesday, April 07, 2009 3:17 PM
    • Unmarked as answer by Me.Saqib Tuesday, April 07, 2009 3:17 PM
    • Marked as answer by Me.Saqib Tuesday, April 07, 2009 9:31 PM
    Tuesday, April 07, 2009 3:13 PM

All replies

  • And where is the base address ?
    Friday, April 03, 2009 3:03 PM
  • I m not if its important... because i have also another project where I dont have this. So I really didnt pay much attention to it.
    What is it and What value it should hold?

    I did added as but DIDNT work
    host>
    <
    baseAddresses>
    <
    add baseAddress = "http://localhost:8731/Design_Time_Addresses/Client_STS/Service1/" />
    </
    baseAddresses>
    </
    host>

    <


    Regards

    Friday, April 03, 2009 3:25 PM
  • Hi Saqib,

    it is important because you have an endpoint that uses the HTTP protocol ("mex").

    How is your service hosted? If you for example host your service in a Windows service you should move the configuration parameters to its config file.

    Please provide more info. You could also paste your code (including the config file).

    Regards,
    John
    Friday, April 03, 2009 6:57 PM
  • Its self hosted in form application. (Just One Project)

    I started it by creating the New Project -> WCF -> WCF Service Library.

    Then I added a Form that is calling the following method on the onload event: (I hope this is right way of doing it...).

    Private
    Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim serviceHost As ServiceHost = New ServiceHost(GetType(ClientService))
    serviceHost.Open()
    End Sub

    Here is my complete App.config file

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <appSettings>
        <add key="queueName"  value=".\private$\clientqueue"/>
      </appSettings>
      <system.serviceModel>
        <services>
          <service name="Client_STS.ClientService" behaviorConfiguration="Client_STS.Service1Behavior">
            <host>
              <baseAddresses>
                <add baseAddress="http://localhost:8731/Design_Time_Addresses/Client_STS/ClientService/" />            
              </baseAddresses>
            </host>
            <endpoint address="net.msmq://localhost/private/clientqueue" 
                 binding="netMsmqBinding"
                 contract="Client_STS.IClient">
              <identity>
                <dns value="localhost"/>
              </identity>
            </endpoint>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
          </service>
        </services>
    
        <client>
          <endpoint address="net.msmq://63.97.174.37/private/serverqueue" binding="netMsmqBinding"
              bindingConfiguration="NetMsmqBinding_IServer" contract="IServer"
              name="NetMsmqBinding_IServer" />
        </client>
    
        <bindings>
          <netMsmqBinding>
            <binding name="NetMsmqBinding_IServer" closeTimeout="00:01:00"
                openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                deadLetterQueue="System" durable="true" exactlyOnce="true"
                maxReceivedMessageSize="65536" maxRetryCycles="2" receiveErrorHandling="Fault"
                receiveRetryCount="5" retryCycleDelay="00:30:00" timeToLive="1.00:00:00"
                useSourceJournal="false" useMsmqTracing="false" queueTransferProtocol="Srmp"
                maxBufferPoolSize="524288" useActiveDirectory="false">
              <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                  maxBytesPerRead="4096" maxNameTableCharCount="16384" />
              <security mode="None">
                <transport msmqAuthenticationMode="None" msmqEncryptionAlgorithm="RC4Stream"
                    msmqProtectionLevel="None" msmqSecureHashAlgorithm="Sha1" />
                <message clientCredentialType="Windows" />
              </security>
            </binding>
          </netMsmqBinding>
        </bindings>
    
    
        <behaviors>
          <serviceBehaviors>
            <behavior name="Client_STS.Service1Behavior">
              <!-- To avoid disclosing metadata information, 
              set the value below to false and remove the metadata endpoint above before deployment -->
              <serviceMetadata httpGetEnabled="True" httpGetUrl="http://localhost:8731/Design_Time_Addresses/Client_STS/ClientService/"/>
              <!-- 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>
    
    Friday, April 03, 2009 7:40 PM
  • Did you move the config file from the WCF Service Library project to the Windows Forms project? If not, please do so.

    You should initialize your WCF service in the constructor of the form you're using.

    Did this help?

    Regards,
    John
    Friday, April 03, 2009 8:24 PM
  • I started by creating the New Project -> WCF -> WCF Service Library.

    Then I added a Form in the same project. I didnt add a new project. Its only one App.config file in One whole Project.

    I dont have 2 projects.

    Friday, April 03, 2009 8:34 PM
  • From arhitectural point of view you should have two projects, a WCF Service Library project and a Windows Forms project.
    With this 'layout' you need to add the reference to the WCF Service Library assembly in you Forms project (and move the config file).

    If you want to put it all in the same project, I suggest you first create a Windows Forms project and then add the WCF service component to it (right-click the project and select Add -> Component -> WCF Service).

    You could change the type of you current project (right click the project, select Properties -> Application and change the Output type to Windows application) but you'll have to do some adjustments (implement the method Main).

    Service Library projects are compiled as DLLs and are not meant to be run directly as e.g. Console projects.

    Hope this helps!

    Regards,
    John
    • Marked as answer by Me.Saqib Tuesday, April 07, 2009 9:32 PM
    Friday, April 03, 2009 8:49 PM
  • You could change the type of you current project (right click the project, select Properties -> Application and change the Output type to Windows application) but you'll have to do some adjustments (implement the method Main).


    And that's what I did.
    I went to Properties -> Application and change the Application Type to "Windows Forms Application" and then on Startup  Object, I changed it to Form1.
    Note: I dont have main method in my form. Do I need to have a Main method in the form???

    I tried adding the Main Method in Module file and then Changed the Start Up object to  "MainModule" / "Sub Main" BUT NO LUCK...

    Friday, April 03, 2009 9:12 PM
  • You need to add a <serviceMetadata/> behavior into the Client_STS.Service1Behavior behavior section
    Richard Blewett, thinktecture - http://www.dotnetconsult.co.uk/weblog2
    Saturday, April 04, 2009 7:05 AM
  • <behaviors>
          <serviceBehaviors>
            <behavior name="Client_STS.Service1Behavior">
              <!-- To avoid disclosing metadata information,
              set the value below to false and remove the metadata endpoint above before deployment -->
              <serviceMetadata httpGetEnabled="True" httpGetUrl="http://localhost:8731/Design_Time_Addresses/Client_STS/ClientService/"/>
              <!-- 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>

    Its already there....Its not commented out but still appeared as comment..
    Sunday, April 05, 2009 3:00 AM
  • Ahh sorry - syntax highlighting threw me

    Can you go to the build directory and tell us what you have in there. You should have a <yourproject>.exe and a <yourproject>.exe.config (plus a few other bits and pieces) and the <yourproject>.exe.config should contain your WCF configuration
    Richard Blewett, thinktecture - http://www.dotnetconsult.co.uk/weblog2
    Sunday, April 05, 2009 4:58 AM
  • I have Project Name, references, bin,obj, Form1, IService1.vb,Service1.vb,App.Config file

    Under bin, I have debug and release folders.

    Release folder has: Client_STS_SingleProj.exe,Client_STS_SingleProj.exe.Config, ...pdb, ...xml files.


    Regards

    Monday, April 06, 2009 3:29 AM
  • And Client_STS_SingleProj.exe.Config contains the WCF configuration you are expecting?
    Richard Blewett, thinktecture - http://www.dotnetconsult.co.uk/weblog2
    Monday, April 06, 2009 7:30 AM
  • Its exactly same as I pasted above.

    Regards
    Monday, April 06, 2009 2:12 PM
  • When you run Client_STS_SingleProj.exe do you get an error or just when you try to get metadata?
    Richard Blewett, thinktecture - http://www.dotnetconsult.co.uk/weblog2
    Monday, April 06, 2009 2:25 PM
  • Yes, when I double clicked the exe, I got .Net Framework error saying
    "Unhandled exception has occurred in your application. If you Click Continue, the application will ignore this error and attempt......."
    Service "ClientService" has zero application (non=infrastructure) endpoints. This might be because no config file was found for your application or becuase no service element matching the service name could be found in the config file, or because no endpoints were defined in the service element"


    If i click contniue, my form comes up and able to send message but doesnt host himself as a service so it can also see its message que....

    Regards
    Monday, April 06, 2009 3:05 PM
  • So in your config you have the type Client_STS.ClientService  is the ClientService type definitely in that namespace?

    Does the ClientService class have a ServiceBehavior atttribute specifying the ConfigurationName?

    Richard Blewett, thinktecture - http://www.dotnetconsult.co.uk/weblog2
    Monday, April 06, 2009 3:12 PM
  • This is in my service.vb file

    <ServiceBehavior()> _

    Public Class ClientService
    Implements IClient

    App.config
    <service name="Client_STS.ClientService" behaviorConfiguration="Client_STS.Service1Behavior">
    .
    .
    .
    .

    <behaviors>
    <
    serviceBehaviors>
    <
    behavior name="Client_STS.Service1Behavior">
    <serviceMetadata httpGetEnabled="True" httpGetUrl="http://localhost:8731/Design_Time_Addresses/Client_STS/ClientService/"/>
    <serviceDebug includeExceptionDetailInFaults="False" /></behavior>
    </
    serviceBehaviors>
    </
    behaviors>

    Monday, April 06, 2009 3:42 PM
  • I suspect that the ClientService class isn't in that namespace. In your Main can you put the code

    MessageBox.Show( GetType(ClientService).FullName)

    and lets find out what the fully qualified name of the ClientService is

    As an aside, why do you have the ServiceBehavior attribute in place if you don;t set any values on it?
    Richard Blewett, thinktecture - http://www.dotnetconsult.co.uk/weblog2
    Monday, April 06, 2009 3:45 PM
  • I added the msgbox and recompiled and double clicked the exe. I got the msgbox with value "ClientService" word only. Then the error pop up and same flow as I mentioned above.

    Note: I couldnt even able to run from IDE the above test. I had to compile and do the test off of exe.

    Regarding Servicebehavior attribute, I m not sure. I can delete it.

    Monday, April 06, 2009 4:39 PM
  • I think you are right...Its the namespace issue but its really strange.

    If I have proj and I have class, I access the class name as <myproj>.className to create an object of it.

    So after removing all the <myproj> words, the  service finally pop up again .

    I changed

    <

    And

    endpoint address="net.msmq://localhost/private/clientqueue"  binding="netMsmqBinding" contract="Client_STS_SingleProj.IClient">
    To
    <endpoint address="net.msmq://localhost/private/clientqueue"  binding="netMsmqBinding" contract="IClient">

    and it worked. (STill having an issue)

    1. I never understood why IT WOULD DO THIS TO ME????
    2. I wanted to host my service in the form but again I m getting the default the box where your service is hosted on localhost and service methods on the side to test...

    <

    service name="Client_STS_SingleProj.ClientService" behaviorConfiguration="Client_STS.Service1Behavior">
    To
    <
    service name="ClientService" behaviorConfiguration="Client_STS.Service1Behavior">

     

    • Marked as answer by Me.Saqib Tuesday, April 07, 2009 9:31 PM
    Monday, April 06, 2009 4:54 PM
  • well in moving your code around you have taken the class out of the namespace and so thats why the config doesn;t work

    I have no idea what you mean by 2. - you need to run the .exe to run the service
    Richard Blewett, thinktecture - http://www.dotnetconsult.co.uk/weblog2
    • Marked as answer by Me.Saqib Tuesday, April 07, 2009 9:33 PM
    Monday, April 06, 2009 6:35 PM
  • I mean to say why my Form doesnt fire up on when I run the code?

    When I run the code, I get the WCF Test Client box to test the service instead of my Form Application that ought to be hosting the application !!!

    Tuesday, April 07, 2009 1:53 AM
  • I assume you mean when you run it from Visual Studio as opposed to running the .exe directly. What happens when you run the .exe directly? Does it run successfully?


    Richard Blewett, thinktecture - http://www.dotnetconsult.co.uk/weblog2
    Tuesday, April 07, 2009 8:13 AM
  • That's strange.
    Yep, it runs as a Service hosted in my Form app and works fine.

    But in my other proj, even when I ran the code in debug mode / Visual studio, I still get an Form app or Console App (whatever I m using for hosting)  rather than default "WCF Test Client" itself.

    Regards
    Tuesday, April 07, 2009 2:46 PM
  • The problem is that WCFServiceLibrary projects are "special" in that you can run them without providing your own host because teh WCFServiceHost process gets instantiated for you. Changing the project type doesn;t appear to change this behavior - the general idea is you create a second project to host the library - referencing the library from the hosting process - then you run the host and the service gets hosted. You need to remember to copy the configuration from the library to the hosting process as config files are application rather than library specific in .NET
    Richard Blewett, thinktecture - http://www.dotnetconsult.co.uk/weblog2
    • Marked as answer by Me.Saqib Tuesday, April 07, 2009 3:17 PM
    • Unmarked as answer by Me.Saqib Tuesday, April 07, 2009 3:17 PM
    • Marked as answer by Me.Saqib Tuesday, April 07, 2009 9:31 PM
    Tuesday, April 07, 2009 3:13 PM
  • Hi,

    I got the same problem and also found the solution.

    Problem:

    Just ensure that you have changed the namespace any where in the class files only. If you do so and run the service then you get the error as you mentioned "

    The client was unable to retrieve service metadata. MAke sure the service is running and exposing metadata"

    Solution:

    1. You need to recall the old name space you used to have before changing.

    2. Now copy that old namespace and hit Ctrl+f and paste it in Find what, select "Look in:" option in dropdown to "Entire Solution" 

    and hit F3

    3. If you find the old namespace then simply replace the old namespace with the newly changed namespace.

     

     

     

    Friday, June 03, 2011 5:15 PM
  • I have a very simple web service which was doing fine until today.   Then it started throwing the metadata error when launching the WCF Test Client.

    I tried every solution I could find.

    In the end, I simply recreated the project and copied all the code in as is.

    Then it worked fine.

    I use Visual Studio 2010 and have been having problems of this nature with both web services, and web applications.

    I essentially did the same thing for some .aspx files that would not work until I recreated them.

    There is some deep level config or hidden template or registry entry that must be at work in my opinion.

    At any rate, often the error messages involved are way off from what the problem is, so I've learned to just start from scratch.

    If anyone can chime in and tell me why these types of errors (which obviously have nothing to do with code or configuration, since I just copy the same back into the new project), I would love to hear about it!

     


    John Bailo
    Tuesday, January 10, 2012 8:52 AM