![](/img/trans.png)
[英]How to read an endpoint value from an app.config and pass it to my proxy class for the client?
[英]how to read endpoint address value from app.config
我有asp.net web application
并且我的app.config
文件中包含以下内容。
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="Test" />
<binding name="Test1">
<security mode="Test" />
</binding>
<binding name="BasicHttpBinding_IService1" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://test:90001"
binding="basicHttpBinding" bindingConfiguration="Test"
contract="Test" name="HTTP_Port" />
</client>
</system.serviceModel>
我如何get/read endpoint address
值?
我遇到了这个解决方案,但它不适用于我要求exe文件路径。 不确定哪个exe路径文件?
var serviceModel = ServiceModelSectionGroup.GetSectionGroup(ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None));
var endpoints = serviceModel.Client.Endpoints;
foreach (ChannelEndpointElement e in endpoints)
{
if (e.Name == "HTTP_Port")
Console.WriteLine(e.Address);
}
Console.ReadLine();
要从appconfig中读取端点,您需要添加System.ServiceModel.Configuration的引用,并使用GetSectionGroup方法返回serviceModel组,并且您可以访问该部分中的所有端点,如果只需要一个可以使用端点名称访问的端点。
同样在appconfig中,您提供的端口无效,在读取带有该端口的url时出现错误,我假设您只是添加了该示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.