【问题标题】:Getting MIME type from Web Service Response header从 Web 服务响应标头获取 MIME 类型
【发布时间】:2012-03-20 23:17:16
【问题描述】:

我调用了由外部合作伙伴公司提供的 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 服务的类型是什么?它是基于 SOAP 的 Web 服务,还是 RESTful Web 服务?
  • 这是一个 SOAP Web 服务。合作伙伴公司的开发人员告诉我,在 Web 服务的响应标头中有有关内容类型的数据。我的问题是如何从我的代码中提取这些信息?
  • 如果您有权访问 Web 服务的 WSDL,请发布所需 Web 方法的 SOAP 请求/响应示例

标签: c# web-services header content-type


【解决方案1】:

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 服务应该提供功能来获取它?

(由于要复制的代码,我提供了答案,而不是评论)

【讨论】:

    猜你喜欢
    • 2011-04-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多