简体   繁体   中英

IndexOutOfRangeException in MessageSecurityOverHttpElement when creating WCF client from service reference

I have a normal WCF service reference created using 'Add Service Reference' in an application used by thousands of people.

An instance of the client is created using new MyServiceClient() and it works 99% of the time, but for some users it can fail with an IndexOutOfRangeException . I have been unable to reproduce, but from my error reports it seems it might only happen when the application is set to start with Windows, so might be some kind of race condition with some underlying Windows service on startup?

Exception (-2146233080): 
System.IndexOutOfRangeException: Index was outside the bounds of the array. 
at System.Collections.ArrayList.ArrayListEnumeratorSimple.MoveNext() 
at System.Configuration.PropertyInformationCollection..ctor(ConfigurationElement thisElement) 
at System.ServiceModel.Configuration.MessageSecurityOverHttpElement.ApplyConfiguration(MessageSecurityOverHttp security) 
at System.ServiceModel.Configuration.NonDualMessageSecurityOverHttpElement.ApplyConfiguration(NonDualMessageSecurityOverHttp security) 
at System.ServiceModel.Description.ConfigLoader.LookupBinding(String bindingSectionName, String configurationName, BindingCollectionElement bindingCollectionElement, Binding defaultBinding) 
at System.ServiceModel.Description.ConfigLoader.LookupBinding(String bindingSectionName, String configurationName, ContextInformation context)
at System.ServiceModel.Description.ConfigLoader.LoadChannelBehaviors(ServiceEndpoint serviceEndpoint, String configurationName) 
at System.ServiceModel.ChannelFactory.ApplyConfiguration(String configurationName, Configuration configuration) 
at System.ServiceModel.ChannelFactory.InitializeEndpoint(String configurationName, EndpointAddress address) 
at System.ServiceModel.ChannelFactory`1..ctor(String endpointConfigurationName, EndpointAddress remoteAddress) 
at System.ServiceModel.ConfigurationEndpointTrait`1.CreateSimplexFactory() 
at System.ServiceModel.ClientBase`1.CreateChannelFactoryRef(EndpointTrait`1 endpointTrait) 
at System.ServiceModel.ClientBase`1.InitializeChannelFactoryRef()
<system.serviceModel>
  <bindings>
    <wsHttpBinding>
      <binding name="WSHttpBinding_IMyService">
        <security mode="Transport">
          <transport clientCredentialType="None" />
        </security>
      </binding>
    </wsHttpBinding>
  </bindings>
  <client>
    <endpoint address="https://xxxxxxxx.com/Services/MyService.svc" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IMyService" contract="MyService.IMyService" name="WSHttpBinding_IMyService" />
  </client>
</system.serviceModel>

I didn't encounter a similar issue yet. The error indicates that you are trying to access an index in your ArrayList that does not exist in other words out of range.
If the error occurred on the client side, I think it may be that client environment caused this issue. For example, is there a corresponding dotnetframework runtime version installed, system problems? Try to fix these problems then removing and re-adding service references.
Feel free to let me know if the problem still exists.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM