简体   繁体   English

从SOAP .Net Client App跟踪/记录SOAP XML请求和响应以及HTTP状态代码

[英]Trace/Log SOAP XML Request and Response AND HTTP status code from SOAP .Net Client App

I have C# .Net 2.0 App that is client of SOAP web services added to project through WebReferences. 我有C#.Net 2.0 App,它是通过WebReferences添加到项目中的SOAP Web服务的客户端。 .Net creates convenient wrapper classes extending SoapHttpClientProtocol, so that everything like XML and serialization/deserialization of SOAP XML request/response in the communication is hidden. .Net创建了方便的包装器类,扩展了SoapHttpClientProtocol,以便隐藏XML之类的内容以及通信中SOAP XML请求/响应的序列化/反序列化。

I need to log the request and response to the WebServices and especially I want to have the HTTP status codes from the response the HTTP communication. 我需要记录对WebServices的请求和响应,尤其是我想从响应HTTP通信中获取HTTP状态代码。

So far I have implemented SOAP Extension and to get the raw SOAP XML Requests/Responses, however I am unable to get the HTTP status code of the HTTP SOAP Response of the communication? 到目前为止,我已经实现了SOAP扩展并获得了原始的SOAP XML请求/响应,但是我无法获得通信的HTTP SOAP响应的HTTP状态代码?


EDIT: So what I have is an instance of SoapHttpClientProtocol (generated by WSDL) and I want to get the HTTP status code from the communication. 编辑:所以我有一个SoapHttpClientProtocol的实例(由WSDL生成),我想从通信中获取HTTP状态代码。

I decompiled 我反编译

private object[] ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, bool asyncCall)

Curiously there is this condition in it, which actually does not throw error when status 500? 奇怪的是,其中存在这种情况,当状态为500时,它实际上不会引发错误?

if (num1 >= 300 && num1 != 500 && num1 != 400)
{
    throw new WebException(RequestResponseUtils.CreateResponseExceptionString(httpWebResponse, responseStream), null, WebExceptionStatus.ProtocolError, httpWebResponse);
}

EDIT2: So my problem generally is that I have response with HTTP status 500, which actually passes as success, without throwing WebException, due to the code above, which does not work for me, I want to detect such situation, that is why I need the HTTP status code. EDIT2:所以我的问题通常是我收到HTTP状态为500的响应,由于上面的代码对我不起作用,因此我想检测到这种情况,实际上它作为成功传递而没有抛出WebException,我想检测这种情况,这就是为什么需要HTTP状态代码。

HTTP/1.1 500 Internal Server Error

如果需要请求/响应的Http包装器,则可以使用.NET Framework 3.5在C#中尝试类似此类的调用Web API

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

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