我创建了一个类库,它应该连接到我托管的 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/