2012-07-12 2 views
1

나는 다음과 같은 특성이 : 나는 그것을 디버깅 할 때Configuration.GetSection ("은 BasicHttpBinding") app.config 파일에서 해당 섹션을 읽는하지

protected BasicHttpBinding Binding 
{ 
    get 
    { 
     var config = ConfigurationManager.GetSection("basicHttpBinding") as ServiceModelSectionGroup; 
     foreach (ChannelEndpointElement bindings in config.Bindings.BasicHttpBinding.Bindings) 
     { 
      string binding = bindings.Binding; 

      if (binding != null) 
      { 
       return new BasicHttpBinding(binding); 
      } 
     } 
     return null; 
    } 
}   

, 그것은 널 예외와 함께 실패 : 개체 참조가 설정되지 않음 이 줄에있는 개체의 인스턴스 :

foreach (ChannelEndpointElement bindings in config.Bindings.BasicHttpBinding.Bindings) 

그러나 위의 줄도 null임을 알 수 있습니다. 여기

는 실패 왜 내가 알아낼 수없는 app.config 파일

<?xml version="1.0" encoding="utf-8" ?> 
    <configuration> 
     <system.serviceModel> 
      <bindings> 
       <basicHttpBinding> 
        <binding name="IntelexWSSoap" closeTimeout="00:01:00" openTimeout="00:01:00" 
        receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" 
        bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" 
        maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" 
        messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" 
        useDefaultWebProxy="true"> 
        <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" 
        maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
        <security mode="Transport"> 
         <transport clientCredentialType="None" proxyCredentialType="None" 
         realm="" /> 
         <message clientCredentialType="UserName" algorithmSuite="Default" /> 
        </security> 
       </binding> 

..... 

      </basicHttpBinding> 
     </bindings> 
    .... 
    </system.serviceModel> 
</configuration> 

입니다.

+0

새 키워드를 사용하여 시도해보십시오. – MethodMan

+0

중복 : http://stackoverflow.com/q/11451722/1485816. 새 질문을 작성하는 대신 질문에 추가해야합니다. – SNH

+0

@Saied - 삭제했음을 알렸습니다. –

답변

4

이 시도 :

var config = ConfigurationManager.GetSection("system.serviceModel/bindings") as 
         System.ServiceModel.Configuration.BindingsSection; 

<basicHttpBinding>이 구성 섹션 아니라,이 <bindings> 구성 섹션 내의 요소입니다.

+0

감사합니다. 그게 내 config의 문제를 해결 null입니다. 불행히도 내 foreach 루프에서 다른 모든 웜 깡통을 열었습니다. 그것은 channelendpointelements와 내가 시도하고 "foreach 문은 변수를 조작 할 수 없다"라는 공개적 GetEnumerator()의 부재로 인해 모든 것을 시도하고 변경하는 것을 좋아하지 않는다. 내가 알아낼 수있는 것을 조사하고 볼 것이다. –

3

"basicHttpBinding"섹션이 보이지만 null을 반환하는 "system.serviceModel"섹션을 참조하는 ServiceModelSectionGroup으로 캐스팅하려고합니다.

ConfigurationManager.GetSection("system.serviceModel")을 대신 시도하십시오.

+0

이것은 그가 다른 질문에서 가진 것입니다. – SNH

+0

@Saied 아니야. –

관련 문제