正在从Web服务响应标头获取MIME类型

本文关键字:获取 MIME 类型 响应 Web 服务 | 更新日期: 2023-09-27 18:26:31

我调用由外部合作伙伴公司提供的web服务。web服务以字节数组的形式返回文件(.pdf、.dox、.png…)。

如果我需要从代码中获得Header信息(详细地说,我对内容类型数据感兴趣),我如何获得这些信息?

在我们这边,我们使用VS 2010和C#作为语言。

这里的代码:

var client = new PublicService();
wsRequest request = new wsRequest();
var docInfo = new documentInfo();
docInfo.documentId = HSdocumentID;
docInfo.position = 1;
request.documentInfos =  { docInfo };
byte[] doc = client.deliver(deliverRequest);  //returns the file as byte array

正在从Web服务响应标头获取MIME类型

RESPONSE标头看起来像:

<?xml version="1.0" ?>
 <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
  <S:Body><ns2:deliverResponse xmlns:ns2="http://www.dalle.com/webservices/record/2012a">
  <return>
         <Include xmlns="http://www.w3.org/2004/08/xop/include"  
                        href="cid:d3a@example.jaxws.sun.com"/>
  </return></ns2:deliverResponse></S:Body></S:Envelope> 
 Content-Id: <d3a@example.jaxws.sun.com> 
 Content-Transfer-Encoding: binary
 Content-Type: application/pdf    <-- THIS IS THE INFO I NEED TO GET

检查Web方法调用上是否有SOAP标头来回答您的问题

在web方法上,我没有任何引用标头的属性。是否有获取响应标头的通用方法,或者web服务是否应该提供获取它的功能?

(由于要复制的代码,我提供了一个答案,而不是注释)