簡體   English   中英

找不到引用合同的默認終結點元素:通過Powershell cmdlet連接到WCF終結點

[英]Could not find default endpoint element that references contract :connect to WCF endpoint through 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文件導入使用生成的dll文件的模塊。

EDIT2再一次,我沒有引用我的庫的項目。 是Powershell調用已定義的Commandlet,並且這些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;
    }

}

在啟動項目中使用端點創建配置文件

在cmdlet程序集中運行代碼時,執行過程為powershell.exe(在%windir%\\ system32 \\ WindowsPowershell \\ v1.0或%windir%\\ syswow64 \\ WindowsPowershell \\ v1.0中)。需要在powershell配置文件(powershell.exe.config)中定義ServiceModel配置。

我猜這可能不是一個可行的選擇,因此您可能需要手動配置服務客戶端或渠道工廠,而不是通過應用程序配置文件。

參見此處的示例: http : //msdn.microsoft.com/zh-cn/library/ms734681.aspx

另一個選擇是使用激活配置文件: http : //msdn.microsoft.com/zh-cn/library/ff361644.aspx

我不確定這對服務配置元素的效果如何。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM