I have a hand-written WCF proxy in it's own assembly, it's very simple:
public class MyServiceClient : ClientBase<IMyService>, IMyService
{
public MyServiceClient()
{
}
public MyServiceClient(string endpointConfigurationName) :
base(endpointConfigurationName)
{
}
}
I am loading this into a Powershell script:
Add-Type -Path "$LocalPath\MyService.Client.dll"
Add-Type -Path "$LocalPath\MyService.Contracts.dll"
I am then trying to set the App.config (as per other posts on SO) so that the client can be instantiated with an Endpoint defined in config, rather than in the script itself:
[System.AppDomain]::CurrentDomain.SetData("APP_CONFIG_FILE", "$LocalPath\MyService.Client.dll.config")
I have checked the AppDomain and the config file is set as its ConfigurationFile
property.
When I create an instance of the client:
$endpointName = "MyServiceHttpEndpoint" # defined in the app.config file
$myclient = New-Object MyService.Client.MyServiceClient($endpointName)
It falls over saying:
Exception calling ".ctor" with "1" argument(s): "Could not find endpoint element with name 'MyServiceHttpEndpoint' and contract 'MyService.Contracts.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 name could be found in the client element."
Any ideas? I don't want to manually create the endpoint in the script file - it needs to be read from config.