Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not find default endpoint element that references contract :connect to WCF endpoint through Powershell cmdlet

I have created a class library that should connect to a WCF endpoint project I am hosting. The client project has commandlets defined that should interact with the service.

However, I keep getting the following error:

     Could not find default endpoint element that references contract Service1.MyService 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.

Do you know what the problem might be?

EDIT What I have is a single Class Library defining cmdlets. I use an .psd1 file to Import-Module which uses the dll files produced.

EDIT2 Once again, I don't have a project referencing my library. It is the powershell that calls the commandlets defined and these cmdlets should connect to the WCF endpoint

Thanks

like image 321
Saher Ahwal Avatar asked Dec 26 '22 21:12

Saher Ahwal


1 Answers

have got this to work: here is a clean solution:

internal static class ServiceClass
{

    internal static Object GetWCFSvc(string siteUrl)
    {

        Uri serviceUri = new Uri(siteUrl);
        EndpointAddress endpointAddress = new EndpointAddress(serviceUri);

        //Create the binding here
        Binding binding = BindingFactory.CreateInstance();

        ServiceClient client = new ServiceClient(binding, endpointAddress);            
        return client;
    }


}

internal static class BindingFactory
{
    internal static Binding CreateInstance()
    {
        BasicHttpBinding binding = new BasicHttpBinding();
        binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
        binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
        binding.UseDefaultWebProxy = true;
        return binding;
    }

}
like image 193
Saher Ahwal Avatar answered Jan 26 '23 00:01

Saher Ahwal