当.NET 3.5和4.0之间存在差异时,如何在自己的.NET程序中调试本地http服务器?
我正在为 .NET 构建 WebDAV 服务器类库,但遇到了一些困难。
我计划为 .NET 3.5 构建类库,因为它可以被 .NET 3.5 和 4.0 应用程序使用。我有很多来自以前启动的项目的代码,远未完成,但它具有正确的结构,因此我将其复制到一个新的类库项目中,并从新的想法开始。
但是,在使用 .NET 运行时 HttpListener 类提供内容时,.NET 3.5 和 4.0 之间似乎存在一些重大更改。
如何正确调试发送的内容?我尝试了 Fiddler,但它不会从我的程序中获取任何内容,即使我尝试遵循此处的所有提示: 如何在调试 ASP.NET 应用程序时在 Fiddler 中显示本地主机流量?
这篇文章和我的设置之间的区别是我'我当前正在运行一个托管 HttpListener 的普通控制台应用程序,并且我正在从 VMware 7.1 下运行的 Ubuntu 10.04 控制台虚拟机与它进行通信。目前,最好的 WebDAV 单元测试是 litmus 应用程序,我还没有使用它在 Windows 上运行。
我假设这种差异就是为什么 Fiddler 根本不会在我的程序内外获取任何流量。
我认为存在重大更改的原因是,当石蕊应用程序进入第 2 部分(复制/移动)第 4 步(验证服务器不会覆盖,除非被告知)时,它会说:
4. copy_overwrite........ FAIL (COPY overwrites collection: Could not parse response status line)
这是如果我的服务器程序和类库使用.NET 3.5和4.0编译:
4. copy_overwrite........ pass
我制作了一个小型“对象转储器”并转储了发送回的响应对象:
您需要比较这两个如果您想查看它们,请在本地比较程序中进行。
我删除了一些明显会改变的内容,一些内部 ID、一些端口号和类似内容,但其余部分保持原样。
编辑:嗯,正如 Jon 所说,Fiddler 在我当前的设置中并不好,但 Wireshark 确实不错。不幸的是,我还没有更接近问题的解决方案。这是 Wireshark 告诉我要发送的响应数据:
HTTP/1.1 412 Pre HTTP/1.1 412 Pre condition Failed condition Failed ..Transfer-Encod ..Transfer-Encod ing: chunked..Se ing: chunked..Se rver: Microsoft- rver: Microsoft- HTTPAPI/2.0..DAV HTTPAPI/2.0..DAV : 1,2,1#extend.. : 1,2,1#extend.. Date: Wed, 16 Fe Date: Wed, 16 Fe b 2011 15:42:02 b 2011 15:51:34 GMT....0.... GMT....0....
我验证了为这篇文章截断的字节内容,除了时间戳之外,它们是相同的,所以这不是问题。
I am building a WebDAV server class library for .NET and I'm having some difficulties.
I planned on building the class library for .NET 3.5 since it can then be used by both .NET 3.5 and 4.0 applications. I had a lot of code from a previous started project, nowhere near completion, but it had the right structure so I copied it into a new class library project and started with fresh ideas.
However, there seems to be some breaking changes between .NET 3.5 and 4.0 when serving content with the .NET runtime HttpListener class.
How can I properly debug what is sent? I tried Fiddler but it won't pick up anything from my program, even when I tried following all the tips here: How to display localhost traffic in Fiddler while debugging an ASP.NET application?
The difference between that post and my setup is that I'm currently running a normal console application that hosts the HttpListener, and I'm talking to it from an Ubuntu 10.04 console virtual machine running under VMware 7.1. The best unit-testing for WebDAV is currently the litmus application, which I've yet to get running on Windows.
I'm assuming that difference is why Fiddler doesn't pick up any traffic at all in or out of my program.
The reason I think there are breaking changes is that when the litmus application comes to section 2 (copying/moving), step 4 (verify that server does not overwrite unless told to), it says:
4. copy_overwrite........ FAIL (COPY overwrites collection: Could not parse response status line)
This is if my server program and class library is compiled with .NET 3.5, and with 4.0:
4. copy_overwrite........ pass
I made a small "object dumper" and dumped the Response object that is being sent back:
You need to compare those two in a local comparison program if you want to take a look at them.
I've removed some of the things that is obvious will change, some internal Id's, some port numbers and similar, but rest is left as-is.
Edit: Well, as Jon said, Fiddler is no good in my current setup, but Wireshark certainly was. Unfortunately I am no closer to a solution to the problem. This is the response data Wireshark told me I was sending:
HTTP/1.1 412 Pre HTTP/1.1 412 Pre condition Failed condition Failed ..Transfer-Encod ..Transfer-Encod ing: chunked..Se ing: chunked..Se rver: Microsoft- rver: Microsoft- HTTPAPI/2.0..DAV HTTPAPI/2.0..DAV : 1,2,1#extend.. : 1,2,1#extend.. Date: Wed, 16 Fe Date: Wed, 16 Fe b 2011 15:42:02 b 2011 15:51:34 GMT....0.... GMT....0....
I verified the byte contents that I cut off for this post, and apart from the timestamps, they're identical, so this is not the problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您从 Linux 虚拟机发出请求,那么除非您以某种方式在该虚拟机上运行 Fiddler,否则您看不到流量的原因就在于此。 Fiddler 充当客户端的代理。
如果您想查看流量,我建议您尝试使用Wireshark。我希望它在 Windows 或 VM 上可见,只要虚拟网络端口对 Wireshark 可见。
If you're making requests from a Linux VM, then unless you've got Fiddler running on that somehow, that explains why you're not seeing the traffic. Fiddler acts as a proxy for the client.
I suggest you try using Wireshark if you want to see the traffic. I'd expect that to be visible either in Windows or on the VM, so long as the virtual network port is visible to Wireshark.