2016-10-14 3 views
0

나는 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 값을 사용할 수 있습니까?

나는이 solution 건너 왔지만 exe 파일 경로를 묻는 나를 위해 작동하지 않습니다. 어떤 exe 경로 파일을 모르십니까?

답변

0
 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(); 

는 System.ServiceModel.Configuration의 참조를 추가하고 ServiceModel은 서비스 그룹을 반환 방법을 GetSectionGroup 사용할 필요가 appconfig가의 엔드 포인트를 읽으려면 당신은 단지 하나의 당신을 필요로하는 경우는, 해당 섹션의 모든 엔드 포인트에 액세스 할 수 있습니다 엔드 포인트 이름으로 특정 액세스 할 수 있습니다.

또한 appconfig에서 포트가 유효하지 않음을 알았습니다. 해당 포트로 URL을 읽는 동안 오류가 발생했으며 방금 예제로 추가했다고 가정합니다.

+0

동일한 오류 "독립 실행 형 exe 실행하지 않을 때 exePath 지정해야합니다." 나는지고있다. 당신이 말한 것과 정확히 일치합니다. – simbada

+0

@simbada 오류 세부 정보를 스택에 추가 할 수 있습니까? ..! – inan

관련 문제