冠军

导航

在 .NET 下,Fiddler 不再抓取 Web Service 流量问题

在 .NET 下,Fiddler 不再抓取 Web Service 流量问题

问题现象

原来的一个应用中,需要访问 SOAP 服务。在原来的 .NET Framework 版本中,使用 Fiddler 是可以抓取到访问这个 Web Service 的 SOAP 流量的。在迁移到 .NET 之后, Fiddler 就不能再抓取到 SOAP 流量了。

问题分析

Fiddler 通过将自己设置为 WinINET 网络的代理。

在 .NET 环境下,使用了 WCF dotnet-svcutil tool for .NET Core 来生成 Web 服务的客户端代理。

WCF 本身使用 WinHTTP 的网络,而不是 WinINET

WinHTTP 主要被设计用于基于服务器的场景,这些服务器应用使用 HTTP 通讯。

而 WinINet 主要被设计用于桌面应用作为 HTTP 的客户端的场景。WinINet 提供一些用于用户凭据接口的操作,例如收集用户的凭据。在一些场景下,它可以显式网络的错误信息,或者弹出连接网络的窗口。如果你在后台服务上使用它,或者在无人值守的应用上使用它,但是不能处理这些弹出的交互窗口,它就会阻塞你的应用。这就是为什么服务器端不应该使用 WinINet 的原因,除非你确认用户会坐在计算机前面进行交互,可以处理类似 "Setup connection" 之类的对话或者错误信息。

所以,需要将 WinHTTP 网络的代理配置为 Fiddler 所支持的代理。

解决方案

Fiddler 默认已经将代理设置到系统的 WinINet 上,这个代理就是浏览器中使用的代理。所以,我们既可以直接将浏览器的代理同步到 WinHTTP 网络上,也可以手工配置它的代理。

对所有应用使用 IE 的代理配置

在 Windows 上,浏览器的代理被称为 ie 的代理。可以使用下面的方式将它同步到 WinHTTP 上。

使用 netsh winhttp import proxy source=ie 可以将 IE 的代理配置应用到 WinHTTP 网络上。

C:\windows\system32>netsh winhttp import proxy source =ie

Current WinHTTP proxy settings:

    Proxy Server(s) :  http=127.0.0.1:8888;https=127.0.0.1:8888
    Bypass List     :  <-loopback>

检查 WinHTTP 网络代理设置

使用 netsh winhttp show proxy 来检查当前的代理配置。

> netsh winhttp show proxy

Current WinHTTP proxy settings:

    Direct access (no proxy server).

在有代理存在的时候,可以看到当前的代理配置。

> netsh winhttp show proxy

Current WinHTTP proxy settings:

    Proxy Server(s) :  127.0.0.1:8888
    Bypass List     :  (none)

配置 WinHTTP 网络代理

可以手工设置 WinHTTP 使用的代理,使用 netsh winhttp set proxy 配置网络代理。

>netsh winhttp set proxy 127.0.0.1:8888

Current WinHTTP proxy settings:

    Proxy Server(s) :  127.0.0.1:8888
    Bypass List     :  (none

重置 WinHTTP 代理

使用 netsh winhttp reset proxy 命令重置 WinHTTP 网络的代理。

>netsh winhttp reset proxy

Current WinHTTP proxy settings:

    Direct access (no proxy server).

抓取的数据示例

正确配置 WinHTTP 网络的代理之后,就可以使用 Fiddler 抓取到 SOAP 访问的流量。下面是访问 SSRS 服务的一个简单实例。

请求示例

POST http://sample.com/ReportServer/ReportService2010.asmx HTTP/1.1
Host: sample.com
Cache-Control: no-cache, max-age=0
SOAPAction: "http://schemas.microsoft.com/sqlserver/reporting/2010/03/01/ReportServer/FindItems"
Expect: 100-continue
Accept-Encoding: gzip, deflate
Content-Type: text/xml; charset=utf-8
Content-Length: 551

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
           xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <FindItems xmlns="http://schemas.microsoft.com/sqlserver/reporting/2010/03/01/ReportServer">
         <Folder>/Sample</Folder>
         <BooleanOperator>And</BooleanOperator>
         <SearchOptions/>
         <SearchConditions>
            <SearchCondition>
               <Condition>Equals</Condition>
               <Values>
                  <Value>SampleReport</Value></Values>
                  <Name>Name</Name>
            </SearchCondition>
         </SearchConditions>
      </FindItems>
   </s:Body>
</s:Envelope>

响应

HTTP/1.1 200 OK
Cache-Control: private, max-age=0
Content-Length: 1684
Content-Type: text/xml; charset=utf-8
Server: Microsoft-HTTPAPI/2.0
X-AspNet-Version: 4.0.30319
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
Date: Mon, 22 Jul 2024 02:54:55 GMT

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
               xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <soap:Header>
      <ServerInfoHeader xmlns="http://schemas.microsoft.com/sqlserver/reporting/2010/03/01/ReportServer">
         <ReportServerVersionNumber>2018.160.1115.96</ReportServerVersionNumber>
         <ReportServerEdition>Standard</ReportServerEdition>
         <ReportServerVersion>Microsoft SQL Server Reporting Services Version 16.0.1115.96</ReportServerVersion>
         <ReportServerDateTime>2024-07-22T10:54:55</ReportServerDateTime>
         <ReportServerTimeZoneInfo>
            <Bias>-480</Bias>
            <StandardBias>0</StandardBias>
            <StandardDate>
               <year>0</year>
               <month>0</month>
               <dayOfWeek>0</dayOfWeek>
               <day>0</day>
               <hour>0</hour>
               <minute>0</minute>
               <second>0</second>
               <milliseconds>0</milliseconds>
            </StandardDate>
            <DaylightBias>-60</DaylightBias>
            <DaylightDate>
               <year>0</year>
               <month>0</month>
               <dayOfWeek>0</dayOfWeek>
               <day>0</day>
               <hour>0</hour>
               <minute>0</minute>
               <second>0</second>
               <milliseconds>0</milliseconds>
            </DaylightDate>
         </ReportServerTimeZoneInfo>
      </ServerInfoHeader>
   </soap:Header>
   <soap:Body>
      <FindItemsResponse xmlns="http://schemas.microsoft.com/sqlserver/reporting/2010/03/01/ReportServer">
         <Items>
            <CatalogItem>
               <ID>de678150-93d4-4270-ac77-df1d8098f170</ID>
               <Name>SampleReport</Name>
               <Path>/SampleReport</Path>
               <TypeName>Report</TypeName>
               <Size>1381492</Size>
               <CreationDate>2024-06-24T15:24:53.877</CreationDate>
               <ModifiedDate>2024-06-24T15:24:53.877</ModifiedDate>
               <CreatedBy>XXXXX</CreatedBy>
               <ModifiedBy>XXXXXX</ModifiedBy>
               <ItemMetadata />
            </CatalogItem>
         </Items>
      </FindItemsResponse>
   </soap:Body>
</soap:Envelope>

参考

posted on 2024-07-22 17:40  冠军  阅读(5)  评论(0编辑  收藏  举报