I get the following error when i try to consume my wcf service
Could not find endpoint element with name ‘http://localhost:8080/Provider/basic’ and contract ‘Provider.IProvider’ in the ServiceModel client configuration section
I can however connect to my base address through the WCF Test Client on http://localhost:8080/Provider
I’ve tried updating my service reference and that didn’t work, Anyone know what is wrong with my setup
public ServiceHost ProviderServiceHost { get; set; }
private void StartProvider()
{
if (ProviderServiceHost != null)
Abort();
ProviderServiceHost = new ServiceHost(typeof(Provider), new Uri("http://localhost:8080/Provider"));
var binding = new BasicHttpBinding
{
Name = "basicBinding",
HostNameComparisonMode = HostNameComparisonMode.WeakWildcard,
Security = { Mode = BasicHttpSecurityMode.None }
};
var metadataBehavior = ProviderServiceHost.Description.Behaviors.Find<ServiceMetadataBehavior>();
if (metadataBehavior == null)
{
metadataBehavior = new ServiceMetadataBehavior { HttpGetEnabled = true };
ProviderServiceHost.Description.Behaviors.Add(metadataBehavior);
}
ProviderServiceHost.AddServiceEndpoint(typeof(IProvider), binding, "http://localhost:8080/Provider/basic");
ProviderServiceHost.Open();
}
My client is connecting like this
private static ProviderClient _proxy = new ProviderClient(http://localhost:8080/Provider/basic);
If i don’t put in an address then i get this exception
Message “Could not find default endpoint element that references contract ‘Provider.IProvider’ in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.” string
Are you using client side configuration? As it appears you’re using the
ClientBaseproxy I expect you’ve used ‘Add Service Reference…’ and are just the default configuration file.The overload that you’re using is
new ServiceClient(string endpointConfigurationName)– the string value represents a Name, not an Address. If you check your configuration file you should see aclientsection has been added:So if you change your Client constructor to use this Name property it should work better for you.
On the other hand if you are not using a configuration file and want to specify the address in code, you can use a different
ClientBaseconstructor:There are a number of different overloads in the
ClientBaseclass (yourProviderClient) which allow you to specify various properties.