c# - 找不到引用契约(Contract) :connect to WCF endpoint through Powershell cmdlet 的默认终结点元素

标签 c# .net wcf powershell powershell-cmdlet

我创建了一个类库,它应该连接到我托管的 WCF 端点项目。 客户端项目定义了应该与服务交互的命令行开关。

但是,我不断收到以下错误:

     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.

你知道问题可能是什么吗?

编辑 我拥有的是一个定义 cmdlet 的类库。我将 .psd1 文件用于 Import-Module,它使用生成的 dll 文件。

EDIT2 再一次,我没有引用我的库的项目。调用定义的命令行开关的是 powershell,这些 cmdlet 应该连接到 WCF 端点

谢谢

最佳答案

让这个工作:这是一个干净的解决方案:

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

}

关于c# - 找不到引用契约(Contract) :connect to WCF endpoint through Powershell cmdlet 的默认终结点元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11569596/

相关文章:

c# - JSON 反序列化为 KeyValuePair 返回 {null,null}

c# - 如何使用 C# 在 WCF 函数中的单次调用中返回多个列表

c# - 序列包含多个元素

c# - 单元测试中using语句的性能影响

c# - 堆内存问题

C# 从 BindingSource 刷新文本框

c# - 为 ASP.NET Web API 2 应用程序启用 Windows 和基本身份验证

c# - 列表框总是返回所选项目的错误值

c# - 如何在pdf文件中查找空白页

c# - 有哪些工具可用于测试多线程 .net 代码?