【发布时间】:2011-03-12 11:08:49
【问题描述】:
对不起,问题陈述太长了……我花了两天时间调试,有很多笔记……
我有一个 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。
在 MyDataServiceHost 的 bin\Debug\ 文件夹是 MyDataService.exe, app.config 和 MyDataServiceHost.exe.config。 app.config 和 MyDataServiceHost.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.
有什么想法吗?我已经筋疲力尽了谷歌。 :-(
【问题讨论】:
-
可能是错字,但您的错误消息显示:IyDataService。应该是 IMyDataService。
-
是的,这是为了在此处发布而编辑时的拼写错误。已修复,谢谢!
-
请不要在标题中重复诸如“WCF”之类的标签。这就是标签的用途。
-
@CrypticPrime:请您以后保留未编辑的原始版本,如果这是导致错误的原因之一吗?我正在搜索 IyDataService 并且在任何地方都看不到它,这正是我的问题,但是点赞的评论与您的问题内容不符。谢谢
标签: c# visual-studio-2008 wcf app-config