J'ai un proxy WCF écrit à la main dans sa propre assemblée, c'est très simple :
public class MyServiceClient : ClientBase<IMyService>, IMyService
{
public MyServiceClient()
{
}
public MyServiceClient(string endpointConfigurationName) :
base(endpointConfigurationName)
{
}
}
Je charge ceci dans un script Powershell :
Add-Type -Path "$LocalPath\MyService.Client.dll"
Add-Type -Path "$LocalPath\MyService.Contracts.dll"
J'essaie ensuite de définir l'App.config (conformément à l'article 2.2.1). autres postes sur SO) afin que le client puisse être instancié avec un Endpoint défini dans config, plutôt que dans le script lui-même :
[System.AppDomain]::CurrentDomain.SetData("APP_CONFIG_FILE", "$LocalPath\MyService.Client.dll.config")
J'ai vérifié l'AppDomain et le fichier de configuration est défini comme suit ConfigurationFile
propriété.
Lorsque je crée une instance du client :
$endpointName = "MyServiceHttpEndpoint" # defined in the app.config file
$myclient = New-Object MyService.Client.MyServiceClient($endpointName)
Il tombe en disant :
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."
Des idées ? Je ne veux pas créer manuellement le point de terminaison dans le fichier script - il doit être lu depuis la configuration.