<?xml version="1.0"?>
<configuration>
<configSections>
</configSections>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>
</configuration>
No serviceModel
section, as you can see. Should I add it manually, and if so, what should I put in it?
This section is for WCF configuration. In the Tools section in visual studio you have a "WCF Service configuration editor" which help you to create this section. If you don't have this section you must configure it in code, but it is not the best practise.
In this section you have to put the end point, the security settings, bindings, the wcf contract,...
–
If you add the service reference to a library, rather than to your main project (exe, or web application, etc), then the necessary additions will be made (by the Visual Studio tooling) to an app.config
inside the library project, rather than in your main project.
However, at runtime, only the app.config
of the main project is used, so you would need to copy the relevant parts from the (useless) app.config
in the library into the main project's one.
–
I had the same error, and Damien_The_Unbeliever' s answer helped me understand && solve my problem: "However, at runtime, only the app.config of the main project is used".
I was having my wsdl proxy in a class library project. Although my UnitTest project was able to read from that class library's app.config, but at runtime that class lib's app.config became irrelevant.
My solution was to create a partial class for the auto-generated client class and
rely on the System.ServiceModel configured from code instead of reading it from who knows what app.config:
public partial class WsdlClient
public WsdlClient (string endpointUrl, TimeSpan timeout, string username, string password) :
base(WsdlClient.GetBindingForEndpoint(timeout), WsdlClient.GetEndpointAddress(endpointUrl))
this.ChannelFactory.Credentials.UserName.UserName = username;
this.ChannelFactory.Credentials.UserName.Password = password;
private static System.ServiceModel.Channels.Binding GetBindingForEndpoint(TimeSpan timeout)
var httpsBinding = new BasicHttpsBinding();
httpsBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
httpsBinding.Security.Mode = BasicHttpsSecurityMode.Transport;
var integerMaxValue = int.MaxValue;
httpsBinding.MaxBufferSize = integerMaxValue;
httpsBinding.MaxReceivedMessageSize = integerMaxValue;
httpsBinding.ReaderQuotas = System.Xml.XmlDictionaryReaderQuotas.Max;
httpsBinding.AllowCookies = true;
httpsBinding.ReceiveTimeout = timeout;
httpsBinding.SendTimeout = timeout;
httpsBinding.OpenTimeout = timeout;
httpsBinding.CloseTimeout = timeout;
return httpsBinding;
private static System.ServiceModel.EndpointAddress GetEndpointAddress(string endpointUrl)
if (!endpointUrl.StartsWith("https://"))
throw new UriFormatException("The endpoint URL must start with https://.");
return new System.ServiceModel.EndpointAddress(endpointUrl);
WsdlClient MyWsdlClient =>
new WsdlClient (ConfigurationManager.AppSettings["endpointUrl"]
, new TimeSpan(0, 0, 1, 0),
"blabla",
"blabla");
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.