對不起,長期問題陳述...我花了兩天時間調試,並有很多筆記...「找不到名稱爲...的端點元素」
我有一個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 \調試\文件夾是 MyServer.exe,app.config中。
在MyDataSeriviceHost的bin \調試\ 文件夾是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.
任何想法是怎麼回事?我已經用盡了Google。 :-(
可能是一個錯字,但你的錯誤消息讀取:IyDataService。應該可能是IMyDataService。 – 2010-07-06 18:15:13
是的,這是在這裏發佈的編輯錯誤。修正了,謝謝! – CrypticPrime 2010-07-06 18:16:52
請不要在標題中重複「WCF」等標籤。這就是標籤的用途。 – 2010-07-06 18:20:07