views:

36

answers:

2

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

+1  A: 

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.

spinon
I tried that as well. It does not work. Both app.config and MyServer.exe.config are in there (and I tried removing one or the other too just for kicks).
CrypticPrime
Well just for future reference app.config will never work because it won't get picked up. So both applications have the .config file in there with the name matching the name of the current exe. Did you maybe copy the config from the simple app into the complex app and forget to change the name of the config?
spinon
Sadly, I wish this were the case. All file names are correct.
CrypticPrime
Hrmmm...I just noticed that VS is generating MyServer.dll.config and not a *.exe.config file. Is this a problem? Is there some magic I need to do with a DLL?
CrypticPrime
Yes, I see this is not a direct relationship to the simple client that works. The big production app has a BigServer.exe app that loads in all of our code that is compiled into MyServer.dll. Perhaps this should be a separate question on StackOverflow?
CrypticPrime
A: 

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

CrypticPrime