简体   繁体   English

“无法找到名称为...的端点元素”

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

Sorry for the long problem statement...I've spent two days debugging and have a lot of notes... 很抱歉这个问题很长...我花了两天时间调试并且有很多笔记......

I have a WCF data service and another process trying to connect to it as a client via TCP and/or HTTP. 我有一个WCF数据服务和另一个尝试通过TCP和/或HTTP作为客户端连接到它的进程。

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). 我有一个非常简单的测试客户端应用程序似乎连接正常,但更复杂的生产应用程序无法连接(TCP或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. 在这两个客户端项目中,我让Visual Studio 2008使用“添加服务引用”生成app.config,并让它从数据服务中提取元数据。

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");
}
}

In main process: 在主要过程中:

DataServiceManager d = new DataServiceManager();

Here is the app.config file for both simple client and production client: 这是简单客户端和生产客户端的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>
  • In MyServer's bin\\Debug\\ folder is MyServer.exe, app.config. 在MyServer的bin \\ Debug \\文件夹中是MyServer.exe,app.config。

  • In MyDataSeriviceHost's bin\\Debug\\ folder is MyDataService.exe, app.config, and MyDataSeriviceHost.exe.config. 在MyDataSeriviceHost的bin \\ Debug \\文件夹中是MyDataService.exe,app.config和MyDataSeriviceHost.exe.config。 app.config and MyDataSeriviceHost.exe.config are identical. app.config和MyDataSeriviceHost.exe.config是完全相同的。

Here is the error message: 这是错误消息:

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 解决了

It turns out that we have an exe that loads a DLL. 事实证明,我们有一个加载DLL的exe。 The DLL contains the WCF client. 该DLL包含WCF客户端。 When compiled, MyServer.dll.config is generated, but since the exe is native (not .NET) it does not read in a .config file automatically. 编译时,会生成MyServer.dll.config,但由于exe是本机的(不是.NET),因此它不会自动读取.config文件。 We need to do it manually. 我们需要手动完成。 This link allowed me to load the config manually and create a CustomChannelFactory<> to solve this question. 这个链接允许我手动加载配置并创建一个CustomChannelFactory <>来解决这个问题。

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 对于需要相同事物的其他人,这里是导致解决方案的链接: http//www.paraesthesia.com/archive/2008/11/26/reading-wcf-configuration-from-a-custom-location。 ASPX

I had a situation like this, where i had 我有这种情况,我有

  • WCF Service Hosted somewhere WCF服务托管在某个地方
  • Main Project 主要项目
  • Consumer Project of type 'class Library' which has Service reference to a WCF Service “类库”类型的消费者项目,它具有对WCF服务的服务引用
  • Main project calls methods from consumer project 主项目从消费者项目中调用方法

Now the Consumer project had all the related configuration setting in <system.serviceModel> Tag of my app.config, its was still throwing the same error as the above. 现在,Consumer项目在我的app.config的<system.serviceModel>标签中设置了所有相关的配置,它仍然抛出与上面相同的错误。

All i did is added the same tag <system.serviceModel> to my main project's app.config file, and finally we were good to go. 我所做的就是将相同的标签<system.serviceModel>到我的主项目的app.config文件中,最后我们很高兴。

The Real problem, as far as in my case was, it was reading the wrong configuration file. 真正的问题,就我的情况而言,它正在读取错误的配置文件。 Instead of consumer's app.config, it was referring main proj's config. 而不是消费者的app.config,它是指主要的proj的配置。 it took me two hours to figure that out. 我花了两个小时来弄清楚这一点。

Could be just the way you wrote it up but it sounds like your config file is not being copied to the directory correctly. 可能只是你编写的方式,但听起来你的配置文件没有正确复制到目录。 It should have a matching name to your application not app.config. 它应该与您的应用程序具有匹配的名称而不是app.config。 If you try changing the name of the app.config file to [your exe name].exe.config does that help. 如果您尝试将app.config文件的名称更改为[您的exe名称] .exe.config可以帮助您。

When the EXE consumes the DLL the config file it looks for is not DLLName.Dll.Config its EXEName.exe.config , change the name of the generated config file and copy it to the execution path. 当EXE使用DLL时,它查找的配置文件不是DLLName.Dll.Config其EXEName.exe.config,更改生成的配置文件的名称并将其复制到执行路径。 It should work. 它应该工作。

Cheers!!!!!!!!! 干杯!!!!!!!!!

A similar situation with different solution that may be of use in these particular circumstances: 在这些特定情况下可能使用的具有不同解决方案的类似情况:

  • Like the above posts, I have an EXE hosting Client defined in DLL. 像上面的帖子一样,我在DLL中定义了一个EXE托管客户端。

  • Different to above situation is that my Client is using UDP probe to discover Service endpoints (obviously service has MEX enabled) 与上述情况不同的是,我的客户端正在使用UDP探测来发现服务端点(显然服务已启用MEX)

The ClientProxy inherits DuplexClientBase , and overloaded instantiation method allows you to specify binding and endpoint without requiring ANY config files. ClientProxy继承DuplexClientBase ,而重载的实例化方法允许您指定绑定和端点,而无需任何配置文件。

A VB example, I have discovered an endpoint (ep) and I know the binding is TCP with security disabled, so I can instantiate and use callback client as: 一个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