如何获取 SOAP 请求消息的 xml 表示形式?

how to get the xml representation of the SOAP request message?

我有 SOAP Web 服务的 WSDL,我正在通过我的 MVC 应用程序使用它。

通过将 WSDL 作为 Web 服务添加到我的 Visual Studio 解决方案,它会自动为我创建一个代理 class 并为我处理所有 serialization/destabilization 这对我来说真的很棒一会儿。我一直在使用这个代理 class 来 call/send 我对 Web 服务的 SOAP 请求(使用纯 c# 代码并且没有 XML 涉及)并且我收到了我的响应消息并且一切正常.

但是,我现在需要找到发送到 Web 服务的 SOAP 消息的确切 xml 表示形式。我怎么能get/find/make这个?

你可以这样做

var serxml = new System.Xml.Serialization.XmlSerializer(request.GetType());
var ms = new MemoryStream();
serxml.Serialize(ms, request);
string xml = Encoding.UTF8.GetString(ms.ToArray());

其中 xml 是您的原始 SOAP