I\'m just learning wcf and currently got this far.
CS File:
using System;
using System.Collections.Generic;
using System.Linq;
using
You can also get this same error if you are creating your service host programmatically and forget to add the [ServiceContract] and [OperationContract] attributes to the interface contract.
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! :-)
By default, Visual Studio is going to try to setup a client/test ui for you to toy with your new service. To do this it needs to be made aware of the structure and methods your service offers. This is achieved by consuming a definition in the standard WSDL format. However, WCF won't publish this data by default.
You have to setup a metadataexchange endpoint behavior to acehive.
Either post your config file here and we can assist, or google/stack search for metadataexchange and wsdl in WCF
It sounds like you need to add a metadata exchange endpoint:
http://en.csharp-online.net/WCF_Essentials%E2%80%94Metadata_Exchange
// get the <system.serviceModel> / <services> config section
ServicesSection services = ConfigurationManager.GetSection("system.serviceModel/services") as ServicesSection;
ServiceHost host = new ServiceHost(typeof(SelfHostedService.Service));
// enumerate over each <service> node
foreach (ServiceElement aService in services.Services)
{
Console.WriteLine();
Console.WriteLine("Name: {0} / Behavior: {1}", aService.Name, aService.BehaviorConfiguration);
// enumerate over all endpoints for that service
foreach (ServiceEndpointElement see in aService.Endpoints)
{
Console.WriteLine("\tEndpoint: Address = {0} / Binding = {1} / Contract = {2}", see.Address, see.Binding, see.Contract);
//host.AddServiceEndpoint(
}
}
try
{
Console.WriteLine("Service EndPoints are: ");
foreach (ServiceEndpoint endpoint in host.Description.Endpoints)
{
Console.WriteLine("{0} ({1})", endpoint.Address.ToString(), endpoint.Binding.Name);
}
host.Open();
Console.WriteLine(string.Concat("Service is host at ", DateTime.Now.ToString()));
Console.WriteLine("\n Self Host is running... Press <Enter> key to stop");
}
catch(Exception ex)
{
Console.WriteLine(ex.Message.ToString());
}
If still not work so delete current config file and reCreate it with its default name App.config, this is works.
I got this error because my service name was wrong. Using netTcpBinding and mexTcpBinding with httpGetEnabled = False then worked.