WCF Configuration without a config file

Question :

WCF Configuration without a config file,

Answer :

Does anyone know of a good example of how to expose a WCF service programatically without the use of a configuration file? I know the service object model is much richer now with WCF, so I know it’s possible. I just have not seen an example of how to do so. Conversely, I would like to see how consuming without a configuration file is done as well.

Before anyone asks, I have a very specific need to do this without configuration files. I would normally not recommend such a practice, but as I said, there is a very specific need in this case.

Read More  mod_rewrite to alias one file suffix type to another

,

Consuming a web service without a config file is very simple, as I’ve discovered. You simply need to create a binding object and address object and pass them either to the constructor of the client proxy or to a generic ChannelFactory instance. You can look at the default app.config to see what settings to use, then create a static helper method somewhere that instantiates your proxy:

internal static MyServiceSoapClient CreateWebServiceInstance() {      BasicHttpBinding binding = new BasicHttpBinding();      // I think most (or all) of these are defaults--I just copied them from app.config:      binding.SendTimeout = TimeSpan.FromMinutes( 1 );      binding.OpenTimeout = TimeSpan.FromMinutes( 1 );      binding.CloseTimeout = TimeSpan.FromMinutes( 1 );      binding.ReceiveTimeout = TimeSpan.FromMinutes( 10 );      binding.AllowCookies = false;      binding.BypassProxyOnLocal = false;      binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;      binding.MessageEncoding = WSMessageEncoding.Text;      binding.TextEncoding = System.Text.Encoding.UTF8;      binding.TransferMode = TransferMode.Buffered;      binding.UseDefaultWebProxy = true;      return new MyServiceSoapClient( binding, new EndpointAddress( "http://www.mysite.com/MyService.asmx" ) );  }  

That’s the answer WCF Configuration without a config file, Hope this helps those looking for an answer. Then we suggest to do a search for the next question and find the answer only on our site.

Read More  Why go 64 bit OS?

Disclaimer :

The answers provided above are only to be used to guide the learning process. The questions above are open-ended questions, meaning that many answers are not fixed as above. I hope this article can be useful, Thank you