We might be so used to having the config file options for the WCF client applications and it makes life so easy to handle. However, should we ever need to work with no config file scenario, like if we were to build an api kind of interface and expose properties instead of a config file, then we still could do it using code. It can get a little complex but to start let me give you a simple example.
Look at this code snippet that helps to get this idea:
EndpointAddress endpointAddress = new EndpointAddress("http://myServiceURL.com");
WSHttpBinding serviceBinding = new WSHttpBinding();
serviceBinding.ReceiveTimeout = new TimeSpan(0, 0, 120);
MyServiceClient myClient = new MyServiceClient(serviceBinding, endpointAddress);
Love coding!
6 comments:
This was exactly the answer I was looking for - thank you! I built up plugin assemblies to access 3rd party web services and expose them in via a common Interface framework. Being dependent on .config files was definately NOT what I wanted when deploying the plugin's as DLLs, so your pointers in how to hard-code the service properties is great.
One thing I tripped up on that might help others is to use a BasicHttpBinding instead of the WSHttpBinding object when connecting to older-style SOAP (ie not WCF Web Services) services to avoid mis-matches in the envelope expected and exceptions being thrown.
Thanks for your post! :-)
Glad it helped! And thanks for your suggestion.
Pingback from GoTinker (http://www.gotinker.com/2010/03/09/minimal-wcf-serverclient-without-app-config/
THANKS!!! :)
You just made my day. Thank you so much!
Cara, me ajudou bastante.
Post a Comment