c# - WSDL 导出扩展中的周期性异常

标签 c# web-services exception wsdl invalidoperationexception

我有一个 SOAP 服务,现在已经运行了一个多月了。在过去的两周里,我们遇到过服务会随机开始生成异常的情况。每次,它们似乎都与导出扩展有关,并且错误总是沿着以下几行:

An exception was thrown in a call to a WSDL export extension: System.ServiceModel.Description.DataContractSerializerOperationBehavior

“System.ArgumentException:指定节点来自不同的文档上下文。”似乎每次都是根本原因。

让我烦恼的是这项服务在一个半月内没有改变,所以我很困惑我们会突然收到参数错误。这是否更能说明潜在问题(内存泄漏或类似问题)?

我对运行它的机器的访问权限非常有限,但可以根据需要尝试获取任何支持信息。这是 wsdl 返回的完整异常:

    An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is:
    System.InvalidOperationException: An exception was thrown in a call to a WSDL export extension: System.ServiceModel.Description.DataContractSerializerOperationBehavior
     Endpoint: [endpoint name here... hidden for security] ----> System.ArgumentException: The named node is from a different document context.
       at System.Xml.XmlAttributeCollection.Append(XmlAttribute node)
       at System.ServiceModel.Description.SoapHelper.CreateSoapFaultBinding(String name, WsdlEndpointConversionContext endpointContext, FaultBinding wsdlFaultBinding, Boolean isEncoded)
       at System.ServiceModel.Description.MessageContractExporter.MessageBindingExporter.ExportMessageBinding(OperationDescription operation, Type messageContractExporterType)
       at System.ServiceModel.Description.WsdlExporter.CallExtension(WsdlEndpointConversionContext endpointContext, IWsdlExportExtension extension)
       --- End of inner ExceptionDetail stack trace ---
       at System.ServiceModel.Description.ServiceMetadataBehavior.MetadataExtensionInitializer.GenerateMetadata()
       at System.ServiceModel.Description.ServiceMetadataExtension.EnsureInitialized()
       at System.ServiceModel.Description.ServiceMetadataExtension.HttpGetImpl.InitializationData.InitializeFrom(ServiceMetadataExtension extension)
       at System.ServiceModel.Description.ServiceMetadataExtension.HttpGetImpl.GetInitData()
       at System.ServiceModel.Description.ServiceMetadataExtension.HttpGetImpl.TryHandleMetadataRequest(Message httpGetRequest, String[] queries, Message& replyMessage)
       at System.ServiceModel.Description.ServiceMetadataExtension.HttpGetImpl.ProcessHttpRequest(Message httpGetRequest)
       at SyncInvokeGet(Object , Object[] , Object[] )
       at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
       at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
       at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
       at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc)
       at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)

编辑:我想澄清一下服务并不总是会遇到此异常。有时 wsdl 返回正常,其他时候它抛出此异常(我会说目前它是获得成功返回的 50/50 镜头)。我不知道为什么。我最初的想法是环境问题,但如果真是这样,我不知道该向托管团队指出何处。

编辑 2:自从询问初始查询后,我发现客户已将服务放在多台服务器上并正在使用负载平衡器,我相信这解释了我们得到的随机响应。我已经建议他们如何至少隔离问题并从那里着手。

最佳答案

我有一个类似的错误。在我的例子中,事实证明对 WsdlExporter.GetGeneratedMetaData() 的实例调用不是线程安全的,并且是在 Parallel.Foreach 中调用的。所以添加简单的锁定解决了这个问题。

关于c# - WSDL 导出扩展中的周期性异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5939856/

相关文章:

exception - 发送消息到移动API j2me

c# - 不应该在 null 变量上调用 Enumerable.AsEnumerable() 抛出异常吗?

json - 使用 Go 通过 HTTP 发送连续数据

php - 如何使用 Symfony 4 中的事件处理异常?

java - 检查 Axis2 Web 服务中接收到的数据的大小

web-services - 在 Visual Studio 中创建对 PayPal SOAP API 的 Web 服务引用

asp.net - Microsoft.EntityFrameworkCore.dll 中出现类型为 'Microsoft.EntityFrameworkCore.DbUpdateException' 的异常

c# - 将图像转换为 base64 并检查大小

c# - 为什么要通过变量引用事件?

c# - 如何在 C# 中干净地设计并行继承结构?