简体   繁体   English

在C#中使用SOAP Web Service处理格式错误的XML标记

[英]Handling malformed XML tag using SOAP Web Service in C#

I have created an ASMX Web Service to handle requests from a third party application. 我创建了一个ASMX Web服务来处理来自第三方应用程序的请求。 I used a WSDL that they gave us as specs for the request and response. 我使用了WSDL,他们将其作为要求和响应的规范。 I have matched those requirements and have my service up and running. 我已经满足了这些要求,并启动了我的服务。 I can test the application just fine using Storm . 我可以使用Storm很好地测试应用程序。 When we try to access the web service from the third party app, the request fails, so we setup WireShark to watch the requests. 当我们尝试从第三方应用程序访问Web服务时,请求失败,因此我们将WireShark设置为监视请求。

What we saw from the packet captures is "[InvalidOperationException]: Request format is unrecognized for URL unexpectedly ending in /MyMethodName". 从数据包捕获中看到的是“ [InvalidOperationException]:无法识别意外格式为/ MyMethodName结尾的URL的请求格式”。 With a little research, I found this article . 经过一点研究,我发现了这篇文章 We tried that and started receiving a different error message. 我们尝试了这一点,并开始收到其他错误消息。 This was the error message/stack: 这是错误消息/堆栈:

System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at System.Web.Services.Protocols.HttpServerType..ctor(Type type)
   at System.Web.Services.Protocols.HttpServerProtocol.Initialize()
   at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)

I have tried most of the suggestions from the SO article, and decided to take a step back and remove the web service protocols all together from the web config. 我尝试了SO文章中的大多数建议,并决定退后一步,从Web配置中一起删除所有Web服务协议。 So, back to square one as it were. 因此,回到原样。 After further investigation, I noticed that the request being sent to our web service has what I would consider a malformed XML declaration. 经过进一步调查,我注意到发送到我们的Web服务的请求具有我认为格式错误的XML声明。

<?requestXml version='1.0' encoding='UTF-8'?>

Could this be the cause of my headaches? 这可能是我头痛的原因吗? If so, how do I handle this? 如果是这样,我该如何处理? I obviously can't make changes to the third party application. 我显然无法更改第三方应用程序。

I did have to create a generic handler to handle this issue. 我确实必须创建一个通用处理程序来处理此问题。 The XML parser didn't care that the XL declaration tag was malformed. XML解析器并不关心XL声明标签的格式是否正确。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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