Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF service host cannot find any service metadata

Tags:

c#

wcf

I'm just learning wcf and currently got this far.

CS File:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

namespace wcfLib
{            
    [ServiceContract]
    public interface IfaceService
    {
        [OperationContract]
        int wordLen(string word);
    }

    public class StockService : IfaceService
    {
        public int wordLen(string word)
        {
            return word.Length;
        }
    }
}

Yet when I'm trying to run it, it pops an error:

WCF service host cannot find any service metadata...

Any idea what it could be?

Config File:

<system.serviceModel>
   <services>
      <service behaviorConfiguration="wcfLib.Service1Behavior" name="wcfLib.Service1">
        <endpoint address="" binding="wsHttpBinding" contract="wcfLib.ser">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8732/Design_Time_Addresses/wcfLib/Service1/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="wcfLib.Service1Behavior">
          <serviceMetadata httpGetEnabled="True"/>
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
like image 369
Rob Avatar asked Mar 07 '11 15:03

Rob


People also ask

How do I find the metadata of a WCF service?

You can retrieve service metadata using WS-MetadataExchange or HTTP/GET requests by using the ServiceModel Metadata Utility Tool (Svcutil.exe) tool and passing the /target:metadata switch and an address. Svcutil.exe downloads the metadata at the specified address and saves the file to disk.

What is service metadata in WCF?

WCF services use metadata to describe how to interact with the service's endpoints so that tools, such as Svcutil.exe, can automatically generate client code for accessing the service. Most of the types that make up the WCF metadata infrastructure reside in the System. ServiceModel.


4 Answers

I got this exact same issue and was vigorously going through my configuration and everything was inline with the metadata endpoints, etc. The issue? This line:

<service behaviorConfiguration="wcfLib.Service1Behavior" name="wcfLib.Service1">

The name value MUST, MUST have the name of the physical class that is implementing the contract. I forgot... once again and arbitrarily named it thinking it could be any string. So in the case above the implementing class must be named Service1. If the class name changes, make sure to change this value.

This is like WCF 101 stuff and I still get burnt by it even though I have been doing WCF since CTP in Framework 3.0. Blah...

like image 25
atconway Avatar answered Sep 23 '22 07:09

atconway


You need to have the following in your config file:

1) a service behavior for metadata:

<behaviors>
  <serviceBehaviors>
     <behavior name="Metadata"> 
        <serviceMetadata httpGetEnabled="true" />
     </behavior>
  </serviceBehaviors>
</behaviors>

2) reference that service behavior in your service's config

<service name="wcfLib.StockService" 
         behaviorConfiguration="Metadata">
     ....
</service>

*The name value in the service tags in the config file must have the same name as the physical class that is implementing the contract. Remember if the class name changes, make sure to change this value to match.

3) an endpoint for MEX (metadata exchange)

<service name="wcfLib.StockService" 
         behaviorConfiguration="Metadata">
     ....

    <endpoint name="mex"
              address="mex"
              binding="mexHttpBinding"
              contract="IMetadataExchange" />
</service>

With all this in place, things should be just fine! :-)

like image 133
marc_s Avatar answered Sep 23 '22 07:09

marc_s


I had HTTP Activation turned ON. Make sure you have it on.

Ensure HTTP Activation is on

like image 38
Jason Jeyanandan Avatar answered Sep 20 '22 07:09

Jason Jeyanandan


The easiest way to create this problem is to simply re-factor your interface name. It certainly changes the instance name across your project but it fails to update the web.config file. To recreate create a new service, rename your interface and whack F5, boom, metadata dialog appears :-) The answer is as above, just remember to alter your web.config file manually.

Regards

like image 27
Alan Simes Avatar answered Sep 23 '22 07:09

Alan Simes