.NET - deploying a WCF client, without an app.config

前端 未结 2 891
猫巷女王i
猫巷女王i 2020-12-24 14:25

I\'m writing a client to a WCF service. This is a single app in a larger system that includes modules written in C#, C++, VB, and Java. All of the apps share common config

相关标签:
2条回答
  • 2020-12-24 14:38

    You can use the following code to creating the bindings which is what the config is doing. I am not sure whether that will let you remove the file altogether but the application won't use the config if this is the case. Put your own values in the timeouts, etc.

        var binding = new WSHttpBinding();
        binding.SendTimeout = new TimeSpan(0, 0, 0, 0, 100000);
        binding.OpenTimeout = new TimeSpan(0, 0, 0, 0, 100000);
        binding.MaxReceivedMessageSize = 10000;
        binding.ReaderQuotas.MaxStringContentLength = 10000;
        binding.ReaderQuotas.MaxDepth = 10000;
        binding.ReaderQuotas.MaxArrayLength = 10000;
        var endpoint = new EndpointAddress("http://localhost:57102/MyService.svc");
        var myClient = new WebServiceclient(binding, endpoint);
    
    0 讨论(0)
  • 2020-12-24 14:41

    WCF settings can be set in your code, with no need for an external configuration file. Addresses, bindings, endpoints, security, etc. can all be configured in code. This is the best way to be consistent across all of your WCF services and not allow users to tamper with these settings.

    I suggest you expose the address (host name and port number) to users and allow them to configure this somehow because addresses are specific to where your WCF services are hosted.

    0 讨论(0)
提交回复
热议问题