简体   繁体   中英

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

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:

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:

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

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

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

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

I had a situation like this, where i had

  • WCF Service Hosted somewhere
  • Main Project
  • Consumer Project of type 'class Library' which has Service reference to a WCF Service
  • 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.

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.

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. 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. If you try changing the name of the app.config file to [your exe name].exe.config does that help.

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

  • Different to above situation is that my Client is using UDP probe to discover Service endpoints (obviously service has MEX enabled)

The ClientProxy inherits DuplexClientBase , and overloaded instantiation method allows you to specify binding and endpoint without requiring ANY config files.

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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM