【问题标题】:Client found response content type of 'multipart/related客户端发现响应内容类型为“多部分/相关”
【发布时间】:2013-08-19 12:05:54
【问题描述】:

我正在使用网络服务来处理数据。在我看来,我正在正确发送请求。我从 wsdl 添加了 Web 引用并添加了一个安全令牌。但是当我试图得到响应时,它会抛出以下错误:

无效操作异常:“客户端发现响应内容类型为'multipart/related”。

据我了解,我收到以下错误,因为该服务使用 MTOM 发送 pdf 文件。有什么方法可以修复网络引用,因为它可以正确解码 MTOM 而不会出错,或者我应该为它创建一个解码器。并在不使用网络引用的情况下发送请求。

我尝试使用行响应并将其传递给 MTOM 阅读器

 XmlDictionaryReader mtomReader = XmlDictionaryReader.CreateMtomReader(response.GetResponseStream() , Encoding.UTF8, XmlDictionaryReaderQuotas.Max);

但是又出现了一个错误

System.Xml.XmlException:MTOM 消息的 Content-Type 标头不是 找到了。

响应示例:

--MIMEBoundaryurn_uuid_F468164F66D5B7FD071377072332741
Content-Type: application/xop+xml; charset=iso-8859-1; type="text/xml"
Content-Transfer-Encoding: binary
Content-ID: <0.urn:uuid:F468164F66D5B7FD071377072332742@apache.org>

肥皂-xml

--MIMEBoundaryurn_uuid_F468164F66D5B7FD071377072332741
Content-Type: application/pdf
Content-Transfer-Encoding: binary
Content-ID: <urn:uuid:F468164F66D5B7FD071377072332744@apache.org>

PDF二进制

 --MIMEBoundaryurn_uuid_F468164F66D5B7FD071377072332741--

【问题讨论】:

    标签: c# web-services mtom


    【解决方案1】:

    我在使用 ASP.NET 生成的 ChangeService (Rational Synergy) WSDL 文件的代码和设置时遇到了类似的问题。 我还收到了 MIME 标头以及 XML 消息。假设您使用的是服务引用,我必须修改 web.config 文件并进行以下更改

    首先我必须将 HttpBinding 从 basicHttpBinding 修改为 webHttpBinding,添加行为并配置端点。

    在下面的配置中,更改以粗体标记

    <bindings>
      <!--  basicHttpBinding>
        <binding name="ChangeServiceHttpBinding" messageEncoding="Mtom" />
      </basicHttpBinding  -->
      <webHttpBinding>
        <binding name="ChangeServiceHttpBinding" />
      </webHttpBinding>
    </bindings>
    <behaviors>
      <endpointBehaviors>
        <behavior name="webEndpoint">
          <webHttp defaultBodyStyle="Wrapped" defaultOutgoingResponseFormat="Xml"
              helpEnabled="true"/>
        </behavior>
      </endpointBehaviors>
    </behaviors>    
    <client>
      <endpoint address="http://hostname:port_number/change/webservices/ChangeService" 
                binding="webHttpBinding" 
                bindingConfiguration="ChangeServiceHttpBinding"               
                contract="ChangeSynergyService.ChangeService" 
                name="ChangeServiceHttpPort" behaviorConfiguration="webEndpoint" />
    </client>
    

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-11-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-06
      • 2017-04-21
      • 2013-12-01
      • 2011-06-17
      相关资源
      最近更新 更多