WCF Client Configuration: how can I check if endpoint is in config file, and fallback to code if not?

后端 未结 2 884
梦谈多话
梦谈多话 2021-02-04 11:05

Looking to make a Client that sends serialized Message objects back to a server via WCF.

To make things easy for the end-developer (different departments) would be best

2条回答
  •  心在旅途
    2021-02-04 12:01

    I would like to propose improved version of AlexDrenea solution, that uses only special types for configuration sections.

    Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            ServiceModelSectionGroup serviceModelGroup = ServiceModelSectionGroup.GetSectionGroup(configuration);
            if (serviceModelGroup != null)
            {
                ClientSection clientSection = serviceModelGroup.Client;
                //make all your tests about the correcteness of the endpoints here
    
            }
    

提交回复
热议问题