Reputation: 5791
I were studying WCF here http://msdn.microsoft.com/ru-ru/library/bb386386.aspx and I successfully did Testing the Service step. However in Accessing the Service step I faced problems. It builds without any error, but when I tried to write smth to textLabel space and pressed button1 I get the error in button1_Click function, namely
ServiceReference1.Service1Client client = new ServiceReference1.Service1Client();
Error message
Could not find default endpoint element that references contract >'ServiceReference1.IService1' in the service model client configuaration section. This might be because no configuaration file >>was found for your application or because no end point element matching this contract could >>be found in the client element.
I find such code in the app.project file
<endpoint address="http://localhost:8733/Design_Time_Addresses/WcfServiceLibrary1/Service1/"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService11"
contract="ServiceReference1.IService1" name="BasicHttpBinding_IService11" />
I`m 100% sure, that code is without any error, because I copied it from the above site without any modification. So I will be glad to hear your assumptions how fix that.
Upvotes: 0
Views: 1616
Reputation: 1039418
You should specify the name
of the endpoint when constructing the client:
using (var client = new ServiceReference1.Service1Client("BasicHttpBinding_IService11"))
{
client.SomeMethod();
}
or use *
if you have only one endpoint in the config file:
using (var client = new ServiceReference1.Service1Client("*"))
{
client.SomeMethod();
}
The reason you need to specify the name is because you could have multiple endpoints (with different bindings for example) for the same service in the config file and if you do not specify the name the framework wouldn't know which endpoint you want to invoke.
Also notice how I have wrapped the IDisposable
client in a using
statement to ensure proper disposal once you have finished working with it.
Upvotes: 2