Question: I have a WCF Web Service which is referenced from a class library. After the project is run, when creating the service client object from inside a class library, I receive an InvalidOperationException with message:

> 
> Could not find default endpoint element that references contract
>  'MyServiceReference.IMyService' 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.
> 
> 
> 

The code I am using to create the instance is:

```
myServiceClient = new MyServiceClient();

```

where MyServiceClient inherits from

System.ServiceModel.ClientBase

How do I solve this?

Note: I have a seperate console application which simply creates the same service object and makes calls to it and it works without no problems.

Answer: 
Or you can set the endpoint in your code:

<http://msdn.microsoft.com/en-us/library/ms731862.aspx>

```
BasicHttpBinding binding = new BasicHttpBinding();
EndpointAddress address = new EndpointAddress("http://url-to-service/");

// Create a client that is configured with this address and binding.
MyServiceClient client = new MyServiceClient(binding, address);

```
I had a similar case. I had a class-library that called a web service, then I had an .EXE that called the class-lib's .DLL. I think it's the .EXE's config file that is used and not that of the .DLL config. 

But as Richard said above, I had to fully-qualify the namespace. It's a bit of a pain. 
Below is exactly what I changed. The pain is that I had to change it in two places, 
one in the reference.cs that is generated when you create a service reference, and the other in the config file. Thus, everytime I change the web service and do an "Update Reference" I have to make the change to the C# code again. 

1) You must actually change the ConfigurationName in the reference.cs as follows: 

From: `[System.ServiceModel.ServiceContractAttribute(Namespace = "http://TFBIC.RCT.BizTalk.Orchestrations", ConfigurationName = " RCTWebService.WcfService_TFBIC_RCT_BizTalk_Orchestrations")]`

To: `[System.ServiceModel.ServiceContractAttribute(Namespace = "http://TFBIC.RCT.BizTalk.Orchestrations", ConfigurationName = "TFBIC.RCT.HIP.Components.RCTWebService.WcfService_TFBIC_RCT_BizTalk_Orchestrations")]`

2) and then also change the “contract” value in all related app.config (for .dll’s and .exe’s) as follows:

From: 

<endpoint address=<http://nxwtest08bt1.dev.txfb-ins.com/TFBIC.RCT.BizTalk.Orchestrations/WcfService_TFBIC_RCT_BizTalk_Orchestrations.svc>
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding\_ITwoWayAsync"
 contract="RCTWebService.WcfService\_TFBIC\_RCT\_BizTalk\_Orchestrations"
 name="WSHttpBinding\_ITwoWayAsync">

To: 

<endpoint address=<http://nxwtest08bt1.dev.txfb-ins.com/TFBIC.RCT.BizTalk.Orchestrations/WcfService_TFBIC_RCT_BizTalk_Orchestrations.svc>
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding\_ITwoWayAsync"
contract=" TFBIC.RCT.HIP.Components.RCTWebService.WcfService\_TFBIC\_RCT\_BizTalk\_Orchestrations" name="WSHttpBinding\_ITwoWayAsync">

Just to be clear - how did I know what the full namespace was?
The program's namespace was TFBIC.RCT.HIP. Inside that, the C# code has one additional 
namespace statement:

```
namespace RCTHipComponents

```