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>
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.
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.
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...
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! :-)
I had HTTP Activation turned ON. Make sure you have it on.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With