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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With