簡體   English   中英

“無法找到名稱為...的端點元素”

[英]“Could not find endpoint element with name…”

很抱歉這個問題很長...我花了兩天時間調試並且有很多筆記......

我有一個WCF數據服務和另一個嘗試通過TCP和/或HTTP作為客戶端連接到它的進程。

我有一個非常簡單的測試客戶端應用程序似乎連接正常,但更復雜的生產應用程序無法連接(TCP或HTTP)。 在這兩個客戶端項目中,我讓Visual Studio 2008使用“添加服務引用”生成app.config,並讓它從數據服務中提取元數據。

以下是適用於簡單測試客戶端的代碼:

using Client.MyDataService;

namespace Client
{
    class Program
    {
        static void Main(string[] args)
        {
            MyDataServiceClient client = new MyDataServiceClient("net.tcp");

            client.GetRecords();
        }
    }
}

以下是更復雜的生產客戶端的代碼:

DataServiceManager.cs:

using MyServer.MyDataService;

namespace MyServer.DataServiceBridge
{
    class DataServiceManager
    {
        MyDataServiceClient dataServiceClient = new MyDataServiceClient("net.tcp");
}
}

在主要過程中:

DataServiceManager d = new DataServiceManager();

這是簡單客戶端和生產客戶端的app.config文件:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <bindings>
            <netTcpBinding>
                <binding name="net.tcp" closeTimeout="00:01:00" openTimeout="00:01:00"
                    receiveTimeout="00:10:00" sendTimeout="00:01:00" transactionFlow="false"
                    transferMode="Buffered" transactionProtocol="OleTransactions"
                    hostNameComparisonMode="StrongWildcard" listenBacklog="10"
                    maxBufferPoolSize="524288" maxBufferSize="65536" maxConnections="10"
                    maxReceivedMessageSize="65536">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <reliableSession ordered="true" inactivityTimeout="00:10:00"
                        enabled="false" />
                    <security mode="Transport">
                        <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
                        <message clientCredentialType="Windows" />
                    </security>
                </binding>
            </netTcpBinding>
        </bindings>
        <client>
            <endpoint address="net.tcp://localhost:8888/MyDataService"
                binding="netTcpBinding" bindingConfiguration="net.tcp" contract="MyDataService.IMyDataService"
                name="net.tcp">
                <identity>
                    <userPrincipalName value="COMPUTER_NAME\Username" />
                </identity>
            </endpoint>
        </client>
    </system.serviceModel>
</configuration>
  • 在MyServer的bin \\ Debug \\文件夾中是MyServer.exe,app.config。

  • 在MyDataSeriviceHost的bin \\ Debug \\文件夾中是MyDataService.exe,app.config和MyDataSeriviceHost.exe.config。 app.config和MyDataSeriviceHost.exe.config是完全相同的。

這是錯誤消息:

An exception of type 'System.InvalidOperationException' occurred in System.ServiceModel.dll but 
was not handled in user code

Additional information: Could not find endpoint element with name 'net.tcp' and contract
 'MyDataService.IMyDataService' 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 name could be found in the client element.

有什么想法發生了什么? 谷歌已經筋疲力盡了。 :-(

解決了

事實證明,我們有一個加載DLL的exe。 該DLL包含WCF客戶端。 編譯時,會生成MyServer.dll.config,但由於exe是本機的(不是.NET),因此它不會自動讀取.config文件。 我們需要手動完成。 這個鏈接允許我手動加載配置並創建一個CustomChannelFactory <>來解決這個問題。

對於需要相同事物的其他人,這里是導致解決方案的鏈接: http//www.paraesthesia.com/archive/2008/11/26/reading-wcf-configuration-from-a-custom-location。 ASPX

我有這種情況,我有

  • WCF服務托管在某個地方
  • 主要項目
  • “類庫”類型的消費者項目,它具有對WCF服務的服務引用
  • 主項目從消費者項目中調用方法

現在,Consumer項目在我的app.config的<system.serviceModel>標簽中設置了所有相關的配置,它仍然拋出與上面相同的錯誤。

我所做的就是將相同的標簽<system.serviceModel>到我的主項目的app.config文件中,最后我們很高興。

真正的問題,就我的情況而言,它正在讀取錯誤的配置文件。 而不是消費者的app.config,它是指主要的proj的配置。 我花了兩個小時來弄清楚這一點。

可能只是你編寫的方式,但聽起來你的配置文件沒有正確復制到目錄。 它應該與您的應用程序具有匹配的名稱而不是app.config。 如果您嘗試將app.config文件的名稱更改為[您的exe名稱] .exe.config可以幫助您。

當EXE使用DLL時,它查找的配置文件不是DLLName.Dll.Config其EXEName.exe.config,更改生成的配置文件的名稱並將其復制到執行路徑。 它應該工作。

干杯!!!!!!!!!

在這些特定情況下可能使用的具有不同解決方案的類似情況:

  • 像上面的帖子一樣,我在DLL中定義了一個EXE托管客戶端。

  • 與上述情況不同的是,我的客戶端正在使用UDP探測來發現服務端點(顯然服務已啟用MEX)

ClientProxy繼承DuplexClientBase ,而重載的實例化方法允許您指定綁定和端點,而無需任何配置文件。

一個VB的例子,我發現了一個端點(ep),我知道綁定是TCP,安全性被禁用,所以我可以實例化並使用回調客戶端:

myClientProxy = New ClientProxy(New InstanceContext(Me), New NetTcpBinding(SecurityMode.None), ep.Address)

暫無
暫無

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

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