简体   繁体   English

找不到引用合同的默认终结点元素:通过Powershell cmdlet连接到WCF终结点

[英]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. 我创建了一个类库,该类库应连接到我托管的WCF终结点项目。 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. 编辑我有一个定义cmdlet的类库。 I use an .psd1 file to Import-Module which uses the dll files produced. 我使用.psd1文件导入使用生成的dll文件的模块。

EDIT2 Once again, I don't have a project referencing my library. EDIT2再一次,我没有引用我的库的项目。 It is the powershell that calls the commandlets defined and these cmdlets should connect to the WCF endpoint 是Powershell调用已定义的Commandlet,并且这些cmdlet应该连接到WCF端点

Thanks 谢谢

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;
    }

}

在启动项目中使用端点创建配置文件

When you're running the code in your cmdlet assembly, the executing process is powershell.exe (in %windir%\\system32\\WindowsPowershell\\v1.0 or %windir%\\syswow64\\WindowsPowershell\\v1.0), so any System.ServiceModel configuration will be need to be defined in the powershell config file (powershell.exe.config). 在cmdlet程序集中运行代码时,执行过程为powershell.exe(在%windir%\\ system32 \\ WindowsPowershell \\ v1.0或%windir%\\ syswow64 \\ WindowsPowershell \\ v1.0中)。需要在powershell配置文件(powershell.exe.config)中定义ServiceModel配置。

I'm guessing this is probably not a practical option, so you'll probably need to configure your service client or channel factory manually rather than via the application configuration file. 我猜这可能不是一个可行的选择,因此您可能需要手动配置服务客户端或渠道工厂,而不是通过应用程序配置文件。

See here for an example: http://msdn.microsoft.com/en-us/library/ms734681.aspx 参见此处的示例: http : //msdn.microsoft.com/zh-cn/library/ms734681.aspx

Another option may be to use an Activation Configuration File: http://msdn.microsoft.com/en-us/library/ff361644.aspx 另一个选择是使用激活配置文件: http : //msdn.microsoft.com/zh-cn/library/ff361644.aspx

I'm not sure how well this will work for service configuration elements. 我不确定这对服务配置元素的效果如何。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM