如何查看调用WebService时发送的报文,谢谢

解决方案 »

  1.   

    有个软件叫 httpWatch Professional 可以监测浏览器的发送和接收的信息 你如果需要我发个使用教程给你 很简单
      

  2.   

    你用浏览器看下 asmx, 里头列出了每个函数的发送报文格式,
    根据那个格式自己构造报文, 
    用 telnet 也行, putty 也行, 发送到服务器,就能看到完整的服务器响应咬!以这个为例:   [ WebMethod]
       public string Time() {
          return Context.Timestamp.TimeOfDay.ToString();
       }
    我用浏览器查看
    http://localhost:8080/hello.asmx?op=Time其中 soap2 格式请求格式为:POST /hello.asmx HTTP/1.1
    Host: localhost
    Content-Type: application/soap+xml; charset=utf-8
    Content-Length: length<?xml version="1.0" encoding="utf-8"?>
    <soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
      <soap12:Body>
        <Time xmlns="http://tempuri.org/" />
      </soap12:Body>
    </soap12:Envelope>
    注意上面有个文字需要修改, 就是那个 Content-Length: length
    那个长度是 http body 的长度, 我将上面的文字复制入  UltraEdit, 选中 <?xml 到结束的 Envelope> 得知字节数为 308
    于是, 我们的请求 (http request header + request body )就变为
    POST /hello.asmx HTTP/1.1
    Host: localhost
    Content-Type: application/soap+xml; charset=utf-8
    Content-Length: 308<?xml version="1.0" encoding="utf-8"?>
    <soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
      <soap12:Body>
        <Time xmlns="http://tempuri.org/" />
      </soap12:Body>
    </soap12:Envelope>
    于是, 我用 putty 连接到 web server: 
    这时, putty 连接上等待我输入东西, 将上面的文字全部复制, 粘贴入 putty:回车:
    调用成功了, putty 窗口中显示结果了(为了便于查看, 我把xml 加换行空格了):HTTP/1.1 200 OK
    Server: Cassini/2.0.60306.0
    Date: Mon, 25 May 2009 09:06:30 GMT
    X-AspNet-Version: 2.0.50727
    Cache-Control: private, max-age=0
    Content-Type: application/soap+xml; charset=utf-8
    Content-Length: 334
    Connection: Close<?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Body>
      <TimeResponse xmlns="http://tempuri.org/">
      <TimeResult>17:06:29</TimeResult></TimeResponse>
      </soap:Body>
    </soap:Envelope>怎么样, 直观吧
      

  3.   

    为了图方便, 我省略的参数, 不过有参数的 webmethod , 也是如此炮制即可.那个 putty 要用 raw 模式, 同时 close window on exit 要设为 never , 否则, 一收到响应就 '啪' 的关闭了.