提问人:Michael Olsen 提问时间:8/12/2019 最后编辑:EylMMichael Olsen 更新时间:8/13/2019 访问量:175
从服务引用创建 WCF 客户端时,MessageSecurityOverHttpElement 中的 IndexOutOfRangeException
IndexOutOfRangeException in MessageSecurityOverHttpElement when creating WCF client from service reference
问:
我有一个普通的 WCF 服务引用,使用“添加服务引用”在数千人使用的应用程序中创建。
客户端的实例是使用 创建的,它在 99% 的时间内都能正常工作,但对于某些用户来说,它可能会失败,并显示 .我无法重现,但从我的错误报告来看,似乎只有当应用程序设置为使用 Windows 启动时才会发生,因此启动时某些底层 Windows 服务可能存在某种竞争条件?new MyServiceClient()
IndexOutOfRangeException
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>
答:
0赞
Abraham Qian
8/13/2019
#1
我还没有遇到类似的问题。该错误表示您正在尝试访问 ArrayList 中不存在的索引,换句话说,超出范围。
如果错误发生在客户端,我认为可能是客户端环境导致了这个问题。例如,是否安装了相应的 dotnetframework 运行时版本,系统问题?尝试解决这些问题,然后删除并重新添加服务引用。
如果问题仍然存在,请随时告诉我。
评论
0赞
Michael Olsen
8/13/2019
谢谢,但它不是我构造的 ArrayList,它是由 .NET 从配置文件构造的,它适用于 99% 的用户。对于那些失败的人,如果他们重新启动机器,我可以确认它可以工作(尚未确认应用程序重启是否足够)。
0赞
Abraham Qian
8/14/2019
是的,正如您提到的,该服务对大多数用户来说都是可靠的,可以正常调用。对于此特定用户,可能是计算机/操作系统的问题。我建议您安装 Dotnetframework 运行时并再次重新生成客户端项目(再次重新添加服务引用)
评论