I have two projects.
One is a WCF proxy project which references a web service. I want this project to contain all my logic for interacting with the web service.
I also have a test project which I want to call this proxy project.
The problem is that I have all my config settings like end points etc. in the WCF proxy project. When I run it, I get this error saying it can't find the endpoints.
Could not find default endpoint element that references contract 'AlumniWebService.IAlumniWebService' 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.
I have to put all of my WCF web service configuration in the test project in order for me to call the web service.
This web service wil开发者_如何学JAVAl likely be consumed by more than just this test project, and probably by several more web applications so I would like to have my configuration IN the proxy project so as to not have to have several versions.
How do I get the web config for the proxy project to be referenced?
By default, the .NET configuration system does not look at class library config files. They're being created as a sample, as a helper - but they're not being used. You need to put your configuration into the main app that will be using your class library for it to be "activated" and used.
The one thing you could do with a bit of manual work is this:
- put each of the sub-elements of
<system.serviceModel>
into a separate file reference those from your main config:
<system.serviceModel> <behaviors configSource="behaviors.config" /> <bindings configSource="bindings.config" /> <client configSource="client.config" /> </system.serviceModel>
That way you can have one set of "externalized" config files, and reference them from any number of other projects.
Visual Studio doesn't properly know about this and will highlight this as errors - but trust me - it does work! (it's just a VS deficiency that it doesn't understand the configSource=
attribute on any config section)
Those external config files would then contain just the bits for that specific section, so your bindings.config
would look like this:
<?xml version="1.0" encoding="utf-8"?>
<bindings>
<basicHttpBinding>
<binding name="YourBindingName"
receiveTimeout="00:02:00" sendTimeout="00:02:00"
maxBufferSize="512000" maxBufferPoolSize="524288"
maxReceivedMessageSize="512000"
useDefaultWebProxy="false">
<security mode="None" />
</binding>
</basicHttpBinding>
</bindings>
It is possible to import custom web.config(support web.config having some settings for application) into main web.config but I dont think that you can import service endpoints configuration from support web.config to main web.config.
If you are only concerned with configuring the service at your test application , then just add service reference into your test application and Visual Studio will automatically configure your settings at test application depending upon the configuration at your host application.
精彩评论