“找不到名称为...的端点元素"; [英] "Could not find endpoint element with name..."

查看:28
本文介绍了“找不到名称为...的端点元素";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对不起,问题陈述太长了……我花了两天时间调试,有很多笔记……

Sorry for the long problem statement...I've spent two days debugging and have a lot of notes...

我有一个 WCF 数据服务和另一个试图通过 TCP 和/或 HTTP 作为客户端连接到它的进程.

I have a WCF data service and another process trying to connect to it as a client via TCP and/or HTTP.

我有一个非常简单的测试客户端应用程序,它似乎可以正常连接,但更复杂的生产应用程序无法连接(TCP 或 HTTP 都没有).在这两个客户端项目中,我让 Visual Studio 2008 使用添加服务引用"生成 app.config,并让它从数据服务中提取元数据.

I have a VERY simple test client app that seems to connect fine, but the more complicated production app cannot connect (neither TCP or HTTP). In both client projects, I let Visual Studio 2008 generate the app.config by using "Add Service Reference" and letting it pull metadata from the data service.

这里是简单的测试客户端的代码:

Here is the code for the simple test client that works:

using Client.MyDataService;

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

            client.GetRecords();
        }
    }
}

这是更复杂的生产客户端的代码:

Here is the code for the more complicated, production client:

DataServiceManager.cs:

DataServiceManager.cs:

using MyServer.MyDataService;

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

在主进程中:

DataServiceManager d = new DataServiceManager();

这是简单客户端和生产客户端的 app.config 文件:

Here is the app.config file for both simple client and production client:

<?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.

    • In MyServer's bin\Debug\ folder is MyServer.exe, app.config.

      在 MyDataSeriviceHost 的 bin\Debug\文件夹是 MyDataService.exe,app.config,和MyDataServiceHost.exe.config.app.config 和MyDataServiceHost.exe.config 是相同.

      In MyDataSeriviceHost's bin\Debug\ folder is MyDataService.exe, app.config, and MyDataSeriviceHost.exe.config. app.config and MyDataSeriviceHost.exe.config are identical.

      错误信息如下:

      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.
      

      知道发生了什么吗?我已经用尽了谷歌.:-(

      Any ideas what is going on? I've pretty much exhausted Google. :-(

      推荐答案

      SOLVED

      事实证明,我们有一个加载 DLL 的 exe.DLL 包含 WCF 客户端.编译时,会生成 MyServer.dll.config,但由于 exe 是本机的(不是 .NET),它不会自动读取 .config 文件.我们需要手动完成.此链接允许我手动加载配置并创建 CustomChannelFactory<> 来解决此问题.

      It turns out that we have an exe that loads a DLL. The DLL contains the WCF client. When compiled, MyServer.dll.config is generated, but since the exe is native (not .NET) it does not read in a .config file automatically. We need to do it manually. This link allowed me to load the config manually and create a CustomChannelFactory<> to solve this question.

      对于需要同样事情的任何其他人,这是导致解决方案的链接:http://www.paraesthesia.com/archive/2008/11/26/reading-wcf-configuration-from-a-custom-location.aspx

      For anybody else needing the same thing, here is the link that led to the solution: http://www.paraesthesia.com/archive/2008/11/26/reading-wcf-configuration-from-a-custom-location.aspx

      这篇关于“找不到名称为...的端点元素";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆