This is a concept that has never really been a problem for me until now. In VB.NET, every application automatically generates an app.config file. For years I have just ignored them but lately, as I get tasked to do more and more work with web services they seem to be able to play a useful role. That is mostly with the configuration of bindings and endpoints. I have done all of this in code in the past but I think it would be useful to use the app.config so that in cases where a port number or IP changes I could just change the element data instead of recompiling the project with the change (I actually currently use appsettings for this but you get the idea - I'd like a more complete solution).
So, my problem is that my applications do not seem to recognize the app.config file when the app is deployed on a computer other than my own. Currently I get the dreaded 'Could not find default endpoint element that references contract blahblah' which seems to indicate that my endpoint info is not being read. If I do the same thing in code it works fine.
Is there something extra, beyond just compiling, that I need to do to get the bindings/endpoints etc from app.config to apply?
Code Example (this works):
Dim epa As New EndpointAddress("https://www.mysite.com/devserviceloc/test1.svc")
Dim binding As New BasicHttpBinding
binding.Name = "secureHttpBinding"
binding.Security.Mode = BasicHttpSecurityMode.Transport
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None
binding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None
binding.Security.Transport.Realm = ""
Dim test As New TestingService1.test1Client(binding, epa)
App.config equivalent (does not work)
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<requiredRuntime version="v4.0.20506"/>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="secureHttpBinding">
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
</security >
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://www.mysite.com/devserviceloc/test1.svc" binding="basicHttpBinding"
bindingConfiguration="secureHttpBinding" contract="TestingService1.Itest1"
name="BasicHttpBinding_Itest1" />
</client>
</system.serviceModel>
<system.windows.forms jitDebugging="true" />
</configuration>
When the application is actually built, it needs to be called YourApplication.exe.config
.
You need to rename it to assemblyname.exe.config
if an EXE or assemblyname.dll.config
if it's for a DLL. Visual Studio normally does this for you when you compile. It's still app.config
in the source folder, but should be renamed in the Debug & Release folders.
You can see this mentioned here in the Application Configuration Files section.