Reputation: 673
We want our web applications separated from our WCF web services. We don't want the web app to know if it's hitting any WCF services. Therefore we don't want any WCF web service references defined in the web app assembly.
What I'm trying to do is create a separate WCF wrapper assembly that would contain the WCF service reference and the necessary configuration in the app.config
file. Method in the WCF wrapper would be called from the Web app. When I create the WCF service reference and configuration in the Web App assembly it works fine. When I put the WCF web reference and config file in WCF wrapper assembly it complains about not finding the endpoint. It doesn't look like it's finding the app.config
file in the wrapper assembly.
So in summary I want a structure as follows:
Web app --> WCF wrapper (with WCF service references and config) --> BAL layer --> etc
Config file (web.config if in web app assembly, app.config if in WCF wrapper assembly):
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IEmailValidator" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8080/" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IEmailValidator" contract="EmailProxy.IEmailValidator"
name="BasicHttpBinding_IEmailValidator" />
</client>
</system.serviceModel>
Do I have to create the WCF service references in the web app assembly or can I do it in the WCF wrapper?
Error Message:
Could not find default endpoint element that references contract 'EmailProxy.IEmailValidator' 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 contract could be found in the client element.
Upvotes: 0
Views: 1203
Reputation: 17272
You can load a custom config file via
ExeConfigurationFileMap configMap = new ExeConfigurationFileMap();
configMap.ExeConfigFilename = @"c:\myapp\wcfsettings.config.anything";
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configMap, ConfigurationUserLevel.None);
Upvotes: 0
Reputation: 755083
This goes back to the old truth that the .NET configuration system doesn't support config files for class libraries - it expects the config for a class library to be in the host application that uses the class library - e.g. in your web application.
It's really not a WCF problem - it's a general .NET design decision that the .NET team made. A class library might have an app.config
file in the solution, and that might even be compiled into a myclasslibrary.dll.config
- but that file is not inspected and parsed by the .NET configuration system.
Therefore, in your case, your web app cannot find the config and thus cannot configure any endpoints and that's why it fails.
You basically have three major options:
web.config
Upvotes: 4