在 C# 中,如何捕获 Web 服务调用中使用的 SOAP?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/306852/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 22:30:28  来源:igfitidea点击:

In C#, how would I capture the SOAP used in a web service call?

c#web-servicessoap

提问by David Chappelle

I have a C# application that is a client to a web service. One of my requirements is to allow capturing the SOAP that I send, so that if there is a problem, I can either fix the bug, or demonstrate that the problem is in the service I am calling.

我有一个 C# 应用程序,它是 Web 服务的客户端。我的要求之一是允许捕获我发送的 SOAP,这样如果出现问题,我可以修复错误,或者证明问题出在我调用的服务中。

My WebReference proxy service class derives from System.Web.Services.Protocols.SoapHttpClientProtocolas usual. If I had a magic wand, I would make this base class implement an event OnPostthat I could handle to write the SOAP into my logs and continue.

我的 WebReference 代理服务类System.Web.Services.Protocols.SoapHttpClientProtocol照常派生自。如果我有一个魔杖,我会让这个基类实现一个OnPost我可以处理的事件,以便将 SOAP 写入我的日志并继续。

Short of running a packet sniffer like WireShark, is there an easy way to get this level of logging?

除了运行像 WireShark 这样的数据包嗅探器之外,有没有一种简单的方法来获得这种级别的日志记录?

采纳答案by Zachary Yates

I think what you are looking for is addressed in this question:

我认为您正在寻找的内容在这个问题中得到了解决:

Getting RAW Soap Data from a Web Reference Client running in ASP.net

从 ASP.net 中运行的 Web 参考客户端获取 RAW Soap 数据

It looks like a lot of code though.

不过看起来代码很多。

回答by FlySwat

Take a look at SoapExtensions.

看看SoapExtensions

They are what you need.

它们正是您所需要的。

回答by Moose

If the application is running on your local box and the web service isn't doing anything funky, you can use Fiddler. Fire Up IE, run Fiddler, and you'll see your web service calls go through fiddler's proxy too.

如果应用程序在您的本地机器上运行并且 Web 服务没有做任何奇怪的事情,您可以使用 Fiddler。启动 IE,运行 Fiddler,您将看到您的 Web 服务调用也通过 Fiddler 的代理。

I just used this this morning to do almost the same thing. I had to prove the data my web service was sending wasn't messed up.

我今天早上刚用这个来做几乎同样的事情。我必须证明我的网络服务发送的数据没有搞砸。

回答by Rob Kent

For some reason Fiddler was not showing my local service calls when using the ASP.NET Development Server that comes with Visual Studio. To get around this I changed the web service Url at runtime to be the Fiddler port, just to capture the SOAP message.

出于某种原因,在使用 Visual Studio 附带的 ASP.NET 开发服务器时,Fiddler 没有显示我的本地服务调用。为了解决这个问题,我在运行时将 Web 服务 Url 更改为 Fiddler 端口,只是为了捕获 SOAP 消息。

You can do this from the Immediate window, for example:

您可以从立即窗口执行此操作,例如:

myservice.Url = "localhost:8888" (or whatever port you have Fiddler on)

myservice.Url = "localhost:8888"(或任何你有 Fiddler 的端口)

I used the SoapUI client to test responses.

我使用 SoapUI 客户端来测试响应。

回答by bnieland

To see this traffic in fiddler use the following code:

要在 fiddler 中查看此流量,请使用以下代码:

mySoapHttpClientProtocol.Url = mySoapHttpClientProtocol.Url.Replace("localhost", "localhost.fiddler");

Otherwise, Visual Studio's built in web server will bypass all proxies.

否则,Visual Studio 的内置 Web 服务器将绕过所有代理。

回答by uzay95

Just "." add the address in your endpoint after "localhost". like this:

只是 ”。” 在“localhost”之后添加端点中的地址。像这样:

      <endpoint address="http://localhost.:8868/FEInvoice.asmx" binding="basicHttpBinding"
    bindingConfiguration="FEInvoice_Test" contract="EInvoiceIntegration.FEInvoiceSoap"
    name="FEInvoice_Test" />