WCF: How can I programmatically recreate these App.config values?
Well, the client endpoint in the config specifies this URL:
<endpoint address="http://www.myuri.com/Services/Services.svc/basic"
but in your code sample, you create:
EndpointAddress endpointAddress = new EndpointAddress( "my.uri.com/service.svc" );
The addresses must match - if the one in the config works, you'll need to change your code to:
EndpointAddress endpointAddress = new EndpointAddress( "http://www.myuri.com/Services/Services.svc/basic" );
Mind you - there are various little typos in your code sample (my.uri.com vs. www.myuri.com, /service.svc instead of /Services/Services.svc).
Does it work with the corrected endpoint address?
Marc
Most of the values in the App config are also properties in the binding and can be recreated programatically. Personally, I use a method such as the one below to create the binding
public static BasicHttpBinding CreateBasicHttpBinding()
{
BasicHttpBinding binding = new BasicHttpBinding();
binding.AllowCookies = false;
binding.ReceiveTimeout = new TimeSpan(0, 10, 0);
binding.OpenTimeout = new TimeSpan(0, 1, 0);
binding.SendTimeout = new TimeSpan(0, 1, 0);
// add more based on config file ...
//buffer size
binding.MaxBufferSize = 65536;
binding.MaxBufferPoolSize = 534288;
binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
//quotas
binding.ReaderQuotas.MaxDepth = 32;
binding.ReaderQuotas.MaxStringContentLength = 8192;
// add more based on config file ...
return binding;
}
And I use something like this for creating my Endpoint address
public static EndpointAddress CreateEndPoint()
{
return new EndpointAddress(Configuration.GetServiceUri());
}
The serviceUri will be the service URL such as http://www.myuri.com/Services/Services.svc/basic
Finally to create the service client
Binding httpBinding = CreateBasicHttpBinding();
EndpointAddress address = CreateEndPoint();
var serviceClient = new MyServiceClient(httpBinding, address);