2013-08-19 68 views
0

我正在使用Web服務來處理數據。就我看來,我正在發送請求。我添加了來自wsdl的Web引用並添加了一個安全令牌。但是,當我試圖得到響應,它拋出以下錯誤:客戶端發現響應內容類型爲'multipart/related

Invalid Operation Exception: 「Client found response content type of 'multipart/related".

按我的理解,我得到以下錯誤,因爲該服務使用MTOM發送PDF文件。有什麼方法可以修復網頁引用,因爲它可以正確解碼MTOM,或者我應該爲它創建一個解碼器。併發送請求而不使用Web引用。

我嘗試使用行響應,並把它傳遞給MTOM讀者

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

但是,讓另一個錯誤

System.Xml.XmlException: Content-Type header for MTOM message not found.

響應例如:

--MIMEBoundaryurn_uuid_F468164F66D5B7FD071377072332741 
Content-Type: application/xop+xml; charset=iso-8859-1; type="text/xml" 
Content-Transfer-Encoding: binary 
Content-ID: <0.urn:uuid:[email protected]> 

皁XML

--MIMEBoundaryurn_uuid_F468164F66D5B7FD071377072332741 
Content-Type: application/pdf 
Content-Transfer-Encoding: binary 
Content-ID: <urn:uuid:[email protected]> 

PDF二進制

--MIMEBoundaryurn_uuid_F468164F66D5B7FD071377072332741-- 

回答

0

我曾與ASP.NET類似的問題生成的代碼ChangeService(理性協同)的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> 

希望這有助於

相關問題